Я хочу использовать Hibernate в своем проекте Java EE glassfish Jersey. Но при получении объекта из базы данных он выдает ошибку HHH000142 в одном из связанных классов
Это происходит только при запуске в приложении Java EE. При использовании одного и того же кода только в тесте main.java он отлично работает.
@Entity
public class Attribute {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;
private String name;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "table_id", nullable = false)
private DbTable dbTable;
public Attribute() { }
public Attribute(String name, DbTable dbTable) {
this.name = name;
this.dbTable = dbTable;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public DbTable getDbTable() {
return dbTable;
}
public void setDbTable(DbTable dbTable) {
this.dbTable = dbTable;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
}
Он должен возвратить запрошенный объект как pojo
Трассировка FullStack:
14:58:24.022 [http-bio-8520-exec-1] ERROR o.h.p.p.j.JavassistProxyFactory - HHH000142: Javassist Enhancement failed: domain.database.Attribute
java.lang.ClassCastException: domain.database.Attribute_$$_javassist_8 cannot be cast to javassist.util.proxy.Proxy
at org.hibernate.proxy.pojo.javassist.JavassistProxyFactory.getProxy(JavassistProxyFactory.java:123) ~[hibernate-core-5.2.2.Final.jar:5.2.2.Final]
at org.hibernate.tuple.entity.AbstractEntityTuplizer.createProxy(AbstractEntityTuplizer.java:663) ~[hibernate-core-5.2.2.Final.jar:5.2.2.Final]
at org.hibernate.persister.entity.AbstractEntityPersister.createProxy(AbstractEntityPersister.java:4506) ~[hibernate-core-5.2.2.Final.jar:5.2.2.Final]
at org.hibernate.event.internal.DefaultLoadEventListener.createProxyIfNecessary(DefaultLoadEventListener.java:359) [hibernate-core-5.2.2.Final.jar:5.2.2.Final]
at org.hibernate.event.internal.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:274) [hibernate-core-5.2.2.Final.jar:5.2.2.Final]
at org.hibernate.event.internal.DefaultLoadEventListener.doOnLoad(DefaultLoadEventListener.java:121) [hibernate-core-5.2.2.Final.jar:5.2.2.Final]
at org.hibernate.event.internal.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:89) [hibernate-core-5.2.2.Final.jar:5.2.2.Final]
at org.hibernate.internal.SessionImpl.fireLoad(SessionImpl.java:1218) [hibernate-core-5.2.2.Final.jar:5.2.2.Final]
at org.hibernate.internal.SessionImpl.internalLoad(SessionImpl.java:1101) [hibernate-core-5.2.2.Final.jar:5.2.2.Final]
at org.hibernate.type.EntityType.resolveIdentifier(EntityType.java:639) [hibernate-core-5.2.2.Final.jar:5.2.2.Final]
at org.hibernate.type.EntityType.resolve(EntityType.java:431) [hibernate-core-5.2.2.Final.jar:5.2.2.Final]
at org.hibernate.engine.internal.TwoPhaseLoad.doInitializeEntity(TwoPhaseLoad.java:151) [hibernate-core-5.2.2.Final.jar:5.2.2.Final]
at org.hibernate.engine.internal.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:125) [hibernate-core-5.2.2.Final.jar:5.2.2.Final]
at org.hibernate.loader.plan.exec.process.internal.AbstractRowReader.performTwoPhaseLoad(AbstractRowReader.java:238) [hibernate-core-5.2.2.Final.jar:5.2.2.Final]
at org.hibernate.loader.plan.exec.process.internal.AbstractRowReader.finishUp(AbstractRowReader.java:209) [hibernate-core-5.2.2.Final.jar:5.2.2.Final]
at org.hibernate.loader.plan.exec.process.internal.ResultSetProcessorImpl.extractResults(ResultSetProcessorImpl.java:133) [hibernate-core-5.2.2.Final.jar:5.2.2.Final]
at org.hibernate.loader.plan.exec.internal.AbstractLoadPlanBasedLoader.executeLoad(AbstractLoadPlanBasedLoader.java:122) [hibernate-core-5.2.2.Final.jar:5.2.2.Final]
at org.hibernate.loader.plan.exec.internal.AbstractLoadPlanBasedLoader.executeLoad(AbstractLoadPlanBasedLoader.java:86) [hibernate-core-5.2.2.Final.jar:5.2.2.Final]
at org.hibernate.loader.entity.plan.AbstractLoadPlanBasedEntityLoader.load(AbstractLoadPlanBasedEntityLoader.java:167) [hibernate-core-5.2.2.Final.jar:5.2.2.Final]
at org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:4004) ~[hibernate-core-5.2.2.Final.jar:5.2.2.Final]
at org.hibernate.event.internal.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:508) [hibernate-core-5.2.2.Final.jar:5.2.2.Final]
at org.hibernate.event.internal.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:478) [hibernate-core-5.2.2.Final.jar:5.2.2.Final]
at org.hibernate.event.internal.DefaultLoadEventListener.load(DefaultLoadEventListener.java:219) [hibernate-core-5.2.2.Final.jar:5.2.2.Final]
at org.hibernate.event.internal.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:278) [hibernate-core-5.2.2.Final.jar:5.2.2.Final]
at org.hibernate.event.internal.DefaultLoadEventListener.doOnLoad(DefaultLoadEventListener.java:121) [hibernate-core-5.2.2.Final.jar:5.2.2.Final]
at org.hibernate.event.internal.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:89) [hibernate-core-5.2.2.Final.jar:5.2.2.Final]
at org.hibernate.internal.SessionImpl.fireLoad(SessionImpl.java:1218) [hibernate-core-5.2.2.Final.jar:5.2.2.Final]
at org.hibernate.internal.SessionImpl.access$1900(SessionImpl.java:203) [hibernate-core-5.2.2.Final.jar:5.2.2.Final]
at org.hibernate.internal.SessionImpl$IdentifierLoadAccessImpl.doLoad(SessionImpl.java:2765) [hibernate-core-5.2.2.Final.jar:5.2.2.Final]
at org.hibernate.internal.SessionImpl$IdentifierLoadAccessImpl.load(SessionImpl.java:2739) [hibernate-core-5.2.2.Final.jar:5.2.2.Final]
at org.hibernate.internal.SessionImpl.find(SessionImpl.java:3368) [hibernate-core-5.2.2.Final.jar:5.2.2.Final]
at org.hibernate.internal.SessionImpl.find(SessionImpl.java:3332) [hibernate-core-5.2.2.Final.jar:5.2.2.Final]
at persistance.jpa.AbstractDaoJpaImpl.findById(AbstractDaoJpaImpl.java:35) [classes/:na]
at logic.businessRuleServices.GenerateRule.generate(GenerateRule.java:17) [classes/:na]
at webservices.GenerateRuleResource.GenerateRule(GenerateRuleResource.java:17) [classes/:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_191]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_191]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_191]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_191]
at org.glassfish.jersey.server.model.internal.ResourceMethodInvocationHandlerFactory.lambda$static$0(ResourceMethodInvocationHandlerFactory.java:76) [jersey-server-2.26.jar:na]
at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher$1.run(AbstractJavaResourceMethodDispatcher.java:148) ~[jersey-server-2.26.jar:na]
at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.invoke(AbstractJavaResourceMethodDispatcher.java:191) ~[jersey-server-2.26.jar:na]
at org.glassfish.jersey.server.model.internal.JavaResourceMethodDispatcherProvider$ResponseOutInvoker.doDispatch(JavaResourceMethodDispatcherProvider.java:200) ~[jersey-server-2.26.jar:na]
at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.dispatch(AbstractJavaResourceMethodDispatcher.java:103) ~[jersey-server-2.26.jar:na]
at org.glassfish.jersey.server.model.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:493) ~[jersey-server-2.26.jar:na]
at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:415) ~[jersey-server-2.26.jar:na]
at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:104) ~[jersey-server-2.26.jar:na]
at org.glassfish.jersey.server.ServerRuntime$1.run(ServerRuntime.java:277) ~[jersey-server-2.26.jar:na]
at org.glassfish.jersey.internal.Errors$1.call(Errors.java:272) ~[jersey-common-2.26.jar:na]
at org.glassfish.jersey.internal.Errors$1.call(Errors.java:268) ~[jersey-common-2.26.jar:na]
at org.glassfish.jersey.internal.Errors.process(Errors.java:316) ~[jersey-common-2.26.jar:na]
at org.glassfish.jersey.internal.Errors.process(Errors.java:298) ~[jersey-common-2.26.jar:na]
at org.glassfish.jersey.internal.Errors.process(Errors.java:268) ~[jersey-common-2.26.jar:na]
at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:289) ~[jersey-common-2.26.jar:na]
at org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:256) ~[jersey-server-2.26.jar:na]
at org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:703) ~[jersey-server-2.26.jar:na]
at org.glassfish.jersey.servlet.WebComponent.serviceImpl(WebComponent.java:416) ~[jersey-container-servlet-core-2.26.jar:na]
at org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:370) ~[jersey-container-servlet-core-2.26.jar:na]
at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:389) ~[jersey-container-servlet-core-2.26.jar:na]
at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:342) ~[jersey-container-servlet-core-2.26.jar:na]
at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:229) ~[jersey-container-servlet-core-2.26.jar:na]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303) ~[catalina.jar:7.0.86]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) ~[catalina.jar:7.0.86]
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) ~[tomcat7-websocket.jar:7.0.86]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) ~[catalina.jar:7.0.86]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) ~[catalina.jar:7.0.86]
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219) ~[catalina.jar:7.0.86]
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:110) ~[catalina.jar:7.0.86]
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:498) ~[catalina.jar:7.0.86]
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169) ~[catalina.jar:7.0.86]
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103) ~[catalina.jar:7.0.86]
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:1025) ~[catalina.jar:7.0.86]
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116) ~[catalina.jar:7.0.86]
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:445) ~[catalina.jar:7.0.86]
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1115) ~[tomcat-coyote.jar:7.0.86]
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:637) ~[tomcat-coyote.jar:7.0.86]
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316) ~[tomcat-coyote.jar:7.0.86]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) ~[na:1.8.0_191]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) ~[na:1.8.0_191]
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) ~[tomcat-coyote.jar:7.0.86]
at java.lang.Thread.run(Thread.java:748) ~[na:1.8.0_191]
14:58:24.023 [http-bio-8520-exec-1] INFO o.h.e.i.DefaultLoadEventListener - HHH000327: Error performing load command : org.hibernate.HibernateException: HHH000142: Javassist Enhancement failed: domain.database.Attribute
14:58:24.023 [http-bio-8520-exec-1] DEBUG o.h.r.j.i.ResourceRegistryStandardImpl - HHH000387: ResultSet's statement was not registered
14:58:24.023 [http-bio-8520-exec-1] INFO o.h.e.i.DefaultLoadEventListener - HHH000327: Error performing load command : org.hibernate.HibernateException: HHH000142: Javassist Enhancement failed: domain.database.Attribute
14:58:24.023 [http-bio-8520-exec-1] DEBUG o.h.r.j.i.LogicalConnectionManagedImpl - Initiating JDBC connection release from afterTransaction
14:58:24.030 [http-bio-8520-exec-1] DEBUG o.h.r.t.b.j.i.JdbcResourceLocalTransactionCoordinatorImpl - JDBC transaction marked for rollback-only (exception provided for stack trace)
java.lang.Exception: exception just for purpose of providing stack trace
at org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl$TransactionDriverControlImpl.markRollbackOnly(JdbcResourceLocalTransactionCoordinatorImpl.java:254) ~[hibernate-core-5.2.2.Final.jar:5.2.2.Final]
at org.hibernate.engine.transaction.internal.TransactionImpl.setRollbackOnly(TransactionImpl.java:143) ~[hibernate-core-5.2.2.Final.jar:5.2.2.Final]
at org.hibernate.Transaction.markRollbackOnly(Transaction.java:68) ~[hibernate-core-5.2.2.Final.jar:5.2.2.Final]
at org.hibernate.internal.AbstractSharedSessionContract.markForRollbackOnly(AbstractSharedSessionContract.java:342) [hibernate-core-5.2.2.Final.jar:5.2.2.Final]
at org.hibernate.internal.ExceptionConverterImpl.handlePersistenceException(ExceptionConverterImpl.java:271) [hibernate-core-5.2.2.Final.jar:5.2.2.Final]
at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:148) [hibernate-core-5.2.2.Final.jar:5.2.2.Final]
at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:174) [hibernate-core-5.2.2.Final.jar:5.2.2.Final]
at org.hibernate.internal.SessionImpl.find(SessionImpl.java:3392) [hibernate-core-5.2.2.Final.jar:5.2.2.Final]
at org.hibernate.internal.SessionImpl.find(SessionImpl.java:3332) [hibernate-core-5.2.2.Final.jar:5.2.2.Final]
at persistance.jpa.AbstractDaoJpaImpl.findById(AbstractDaoJpaImpl.java:35) [classes/:na]
at logic.businessRuleServices.GenerateRule.generate(GenerateRule.java:17) [classes/:na]
at webservices.GenerateRuleResource.GenerateRule(GenerateRuleResource.java:17) [classes/:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_191]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_191]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_191]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_191]
at org.glassfish.jersey.server.model.internal.ResourceMethodInvocationHandlerFactory.lambda$static$0(ResourceMethodInvocationHandlerFactory.java:76) [jersey-server-2.26.jar:na]
at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher$1.run(AbstractJavaResourceMethodDispatcher.java:148) ~[jersey-server-2.26.jar:na]
at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.invoke(AbstractJavaResourceMethodDispatcher.java:191) ~[jersey-server-2.26.jar:na]
at org.glassfish.jersey.server.model.internal.JavaResourceMethodDispatcherProvider$ResponseOutInvoker.doDispatch(JavaResourceMethodDispatcherProvider.java:200) ~[jersey-server-2.26.jar:na]
at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.dispatch(AbstractJavaResourceMethodDispatcher.java:103) ~[jersey-server-2.26.jar:na]
at org.glassfish.jersey.server.model.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:493) ~[jersey-server-2.26.jar:na]
at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:415) ~[jersey-server-2.26.jar:na]
at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:104) ~[jersey-server-2.26.jar:na]
at org.glassfish.jersey.server.ServerRuntime$1.run(ServerRuntime.java:277) ~[jersey-server-2.26.jar:na]
at org.glassfish.jersey.internal.Errors$1.call(Errors.java:272) ~[jersey-common-2.26.jar:na]
at org.glassfish.jersey.internal.Errors$1.call(Errors.java:268) ~[jersey-common-2.26.jar:na]
at org.glassfish.jersey.internal.Errors.process(Errors.java:316) ~[jersey-common-2.26.jar:na]
at org.glassfish.jersey.internal.Errors.process(Errors.java:298) ~[jersey-common-2.26.jar:na]
at org.glassfish.jersey.internal.Errors.process(Errors.java:268) ~[jersey-common-2.26.jar:na]
at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:289) ~[jersey-common-2.26.jar:na]
at org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:256) ~[jersey-server-2.26.jar:na]
at org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:703) ~[jersey-server-2.26.jar:na]
at org.glassfish.jersey.servlet.WebComponent.serviceImpl(WebComponent.java:416) ~[jersey-container-servlet-core-2.26.jar:na]
at org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:370) ~[jersey-container-servlet-core-2.26.jar:na]
at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:389) ~[jersey-container-servlet-core-2.26.jar:na]
at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:342) ~[jersey-container-servlet-core-2.26.jar:na]
at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:229) ~[jersey-container-servlet-core-2.26.jar:na]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303) ~[catalina.jar:7.0.86]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) ~[catalina.jar:7.0.86]
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) ~[tomcat7-websocket.jar:7.0.86]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) ~[catalina.jar:7.0.86]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) ~[catalina.jar:7.0.86]
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219) ~[catalina.jar:7.0.86]
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:110) ~[catalina.jar:7.0.86]
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:498) ~[catalina.jar:7.0.86]
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169) ~[catalina.jar:7.0.86]
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103) ~[catalina.jar:7.0.86]
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:1025) ~[catalina.jar:7.0.86]
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116) ~[catalina.jar:7.0.86]
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:445) ~[catalina.jar:7.0.86]
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1115) ~[tomcat-coyote.jar:7.0.86]
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:637) ~[tomcat-coyote.jar:7.0.86]
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316) ~[tomcat-coyote.jar:7.0.86]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) ~[na:1.8.0_191]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) ~[na:1.8.0_191]
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) ~[tomcat-coyote.jar:7.0.86]
at java.lang.Thread.run(Thread.java:748) ~[na:1.8.0_191]