我有一个hibernate方法将一些数据保存到数据库中,它在本地服务器上正常工作但是当它托管它不插入结果到我托管的每个数据库(我的数据库,Web服务)但它没有插入valuse。但是当我在我的本地主机上尝试它的工作正常时,任何人都可以告诉我为什么会这样做
try {
session.beginTransaction();
LabOrder order = (LabOrder) session.get(LabOrder.class, oID);
Lab lab = (Lab) session.get(Lab.class, lID);
speciman.setOrderID(order);
speciman.setLabID(lab);
session.save(speciman);
session.getTransaction().commit();
session.close();
return true;
} catch (RuntimeException ex) {
ex.getMessage();
}
这是我用来保存数据的代码段
错误我正在
Hibernate: select laborder0_.labOrder_ID as labOrder1_1_2_, laborder0_.labOrder_TestID as labOrder2_1_2_, laborder0_.labOrder_SpecimenID as labOrder3_1_2_, laborder0_.labOrder_Location as labOrder4_1_2_, laborder0_.labOrder_Status as labOrder5_1_2_, laborder0_.labOrder_DueDate as labOrder6_1_2_, laborder0_.labOrder_Priority as labOrder7_1_2_, laborder0_.labOrder_Remarks as labOrder8_1_2_, laborder0_.labOrder_LastUpdateUser as labOrder9_1_2_, laborder0_.labOrder_CreateDate as labOrder10_1_2_, laborder0_.labOrder_LastUpdate as labOrder11_1_2_, laborder0_.labOrder_patientID as labOrder12_1_2_, laborder0_.labOrder_CreateUser as labOrder13_1_2_, laborder0_.labOrder_DoctorID as labOrder14_1_2_, testdescri1_.labTestDescription_TestID as labTestD1_0_0_, testdescri1_.labTestDescription_TestName as labTestD2_0_0_, testdescri1_.labTestDescription_TestDescription as labTestD3_0_0_, testdescri1_.labTestDescription_Category as labTestD4_0_0_, testdescri1_.labTestDescription_TestProcedure as labTestD5_0_0_, testdescri1_.labTestDescription_IsSpecimenAvailable as labTestD6_0_0_, testdescri1_.labTestDescription_SpecimenType as labTestD7_0_0_, testdescri1_.labTestDescription_TestResultTableName as labTestD8_0_0_, testdescri1_.labTestdescription_LoincCode as labTestd9_0_0_, testdescri1_.labTestDescription_CreateUser as labTest10_0_0_, testdescri1_.labTestDescription_LastUpdateUser as labTest11_0_0_, testdescri1_.labTestDescription_CreateDate as labTest12_0_0_, testdescri1_.labTestDescription_LastUpdate as labTest13_0_0_, labspecime2_.labSpecimen_ID as labSpeci1_2_1_, labspecime2_.labSpecimen_Status as labSpeci2_2_1_, labspecime2_.labSpecimen_Remarks as labSpeci3_2_1_, labspecime2_.labSpecimen_CollectedBy as labSpeci4_2_1_, labspecime2_.labSpecimen_CollectedDate as labSpeci5_2_1_, labspecime2_.labSpecimen_DeliveredBy as labSpeci6_2_1_, labspecime2_.labSpecimen_DeliveredDate as labSpeci7_2_1_, labspecime2_.labSpecimen_ReceivedBy as labSpeci8_2_1_, labspecime2_.labSpecimen_ReceivedDate as labSpeci9_2_1_, labspecime2_.labSpecimen_CreateUser as labSpec10_2_1_, labspecime2_.labSpecimen_LastUpdateUser as labSpec11_2_1_, labspecime2_.labSpecimen_CreateDate as labSpec12_2_1_, labspecime2_.labSpecimen_LastUpdate as labSpec13_2_1_ from lab_order laborder0_ inner join lab_test_description testdescri1_ on laborder0_.labOrder_TestID=testdescri1_.labTestDescription_TestID left outer join lab_specimen labspecime2_ on laborder0_.labOrder_SpecimenID=labspecime2_.labSpecimen_ID where laborder0_.labOrder_ID=?
java.lang.NullPointerException
at org.hibernate.tuple.AbstractEntityTuplizer.createProxy(AbstractEntityTuplizer.java:372)
at org.hibernate.persister.entity.AbstractEntityPersister.createProxy(AbstractEntityPersister.java:3232)
at org.hibernate.event.def.DefaultLoadEventListener.createProxyIfNecessary(DefaultLoadEventListener.java:237)
at org.hibernate.event.def.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:174)
at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:86)
at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:871)
at org.hibernate.impl.SessionImpl.internalLoad(SessionImpl.java:839)
at org.hibernate.type.EntityType.resolveIdentifier(EntityType.java:266)
at org.hibernate.type.EntityType.resolve(EntityType.java:303)
at org.hibernate.engine.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:116)
at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:842)
at org.hibernate.loader.Loader.doQuery(Loader.java:717)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
at org.hibernate.loader.Loader.loadEntity(Loader.java:1785)
at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:48)
at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:42)
at org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:2821)
at org.hibernate.event.def.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:370)
at org.hibernate.event.def.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:351)
at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:122)
at org.hibernate.event.def.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:178)
at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:86)
at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:871)
at org.hibernate.impl.SessionImpl.get(SessionImpl.java:808)
at org.hibernate.impl.SessionImpl.get(SessionImpl.java:801)
at lib.driver.lab.driverclasses.SpecimenOfBloodSugarResultServiceDriver.saveSpecimen(SpecimenOfBloodSugarResultServiceDriver.java:28)
at lib.classes.labmodel.SpecimenOfBloodSugarResultService.addSpecimenOfBlood(SpecimenOfBloodSugarResultService.java:63)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.sun.jersey.spi.container.JavaMethodInvokerFactory$1.invoke(JavaMethodInvokerFactory.java:60)
at com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$TypeOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:185)
at com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:75)
at com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:302)
at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
at com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:108)
at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
at com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:84)
at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1511)
at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1442)
at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1391)
at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1381)
at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:416)
at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:538)
at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:716)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:225)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:999)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:565)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:307)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
答案 0 :(得分:0)
典型的交易应使用以下习语:
Session sess = factory.openSession();
Transaction tx;
try {
tx = sess.beginTransaction();
//do some work
...
tx.commit();
}
catch (Exception e) {
if (tx!=null) tx.rollback();
throw e;
}
finally {
sess.close();
}