[
https://issues.jboss.org/browse/JBAS-8815?page=com.atlassian.jira.plugin....
]
Viggo Navarsete commented on JBAS-8815:
---------------------------------------
I wasn't able to use the workaround described in the top of this issue (the unwrap),
but I ended up with this:
1. Inject EntityManager
{code}
@PersistenceContext
private EntityManager em;
{code}
2. Get session
{code}
Session session = (Session) em.getDelegate();
{code}
Regression in Hibernate session/sessionfactory injection
--------------------------------------------------------
Key: JBAS-8815
URL:
https://issues.jboss.org/browse/JBAS-8815
Project: JBoss Application Server
Issue Type: Task
Security Level: Public(Everyone can see)
Affects Versions: 6.1.0
Reporter: Scott Marlow
Assignee: Scott Marlow
Fix For: 6.1.0
Regression caused by fix for JBAS-8563. This impacts the Hibernate specific support
mentioned here
http://bill.burkecentral.com/2007/07/06/co-existence-with-hibernate-jpa-a....
The regression is that the following will no longer work:
@PersistenceContext(unitName="custDb") org.hibernate.Session session;
@PersistenceUnit(unitName="custDb") SessionFactory factory;
The workaround is to instead use the JPA 2.0 EntityManager.unwrap(Session.class).
In the following exception, at the point of error. We are in
org.jboss.injection.injector.util.FieldInjectionPoint.set() with:
java.lang.reflect.Field field = org.hibernate.Session
org.jboss.ejb3.test.longlived.HibernateShoppingCartBean.em
this.accessibleObject.type = interface org.hibernate.Session
target is instance of org.jboss.ejb3.test.longlived.HibernateShoppingCartBean
value is instance of org.jboss.jpa.util.ExtendedEntityManager
org.jboss.ejb3.test.longlived.unit.EntityUnitTestCase.testHibernateLongLivedSession
fails with error:
2011-01-18 08:39:08,248 ERROR
[org.jboss.ejb3.proxy.impl.factory.session.stateful.StatefulSessionProxyFactoryBase]
(WorkerThread#1[127.0.0.1:54163]) Could not obtain new Session ID from SFSB Container:
javax.ejb.EJBException: java.lang.IllegalArgumentException: failed to set value
ExtendedEntityManager: persistence.unit:unitName=longlived-test.jar#tempdb on field
org.hibernate.Session org.jboss.ejb3.test.longlived.HibernateShoppingCartBean.em
at org.jboss.ejb3.cache.simple.SimpleStatefulCache.create(SimpleStatefulCache.java:438)
[:1.7.19-SNAPSHOT]
at org.jboss.ejb3.stateful.StatefulContainer.createSession(StatefulContainer.java:440)
[:1.7.19-SNAPSHOT]
at org.jboss.ejb3.session.SessionContainer.createSession(SessionContainer.java:677)
[:1.7.19-SNAPSHOT]
at
org.jboss.ejb3.proxy.impl.factory.session.stateful.StatefulSessionProxyFactoryBase.getNewSessionId(StatefulSessionProxyFactoryBase.java:227)
[:1.0.11]
at
org.jboss.ejb3.proxy.impl.factory.session.stateful.StatefulSessionProxyFactoryBase.createProxyBusiness(StatefulSessionProxyFactoryBase.java:140)
[:1.0.11]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [:1.6.0_23]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
[:1.6.0_23]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
[:1.6.0_23]
at java.lang.reflect.Method.invoke(Method.java:597) [:1.6.0_23]
at org.jboss.aop.Dispatcher.invoke(Dispatcher.java:121) [jboss-aop.jar:2.2.1.GA]
at
org.jboss.aspects.remoting.AOPRemotingInvocationHandler.invoke(AOPRemotingInvocationHandler.java:82)
[:1.0.1.GA]
at org.jboss.remoting.ServerInvoker.invoke(ServerInvoker.java:898) [:]
at
org.jboss.remoting.transport.socket.ServerThread.completeInvocation(ServerThread.java:791)
[:]
at
org.jboss.remoting.transport.socket.ServerThread.processInvocation(ServerThread.java:744)
[:]
at org.jboss.remoting.transport.socket.ServerThread.dorun(ServerThread.java:548) [:]
at org.jboss.remoting.transport.socket.ServerThread.run(ServerThread.java:234) [:]
Caused by: java.lang.IllegalArgumentException: failed to set value ExtendedEntityManager:
persistence.unit:unitName=longlived-test.jar#tempdb on field org.hibernate.Session
org.jboss.ejb3.test.longlived.HibernateShoppingCartBean.em
at
org.jboss.injection.injector.util.FieldInjectionPoint.set(FieldInjectionPoint.java:73)
[:1.0.0-alpha-6]
at org.jboss.injection.injector.EEInjector.inject(EEInjector.java:159) [:1.0.0-alpha-6]
at org.jboss.injection.injector.EEInjector.inject(EEInjector.java:134) [:1.0.0-alpha-6]
at org.jboss.injection.injector.EEInjector.inject(EEInjector.java:82) [:1.0.0-alpha-6]
at
org.jboss.injection.manager.core.DefaultInjectionContext.proceed(DefaultInjectionContext.java:58)
[:1.0.0-alpha-6]
at
org.jboss.injection.manager.core.DefaultInjectionManager.inject(DefaultInjectionManager.java:58)
[:1.0.0-alpha-6]
at
org.jboss.injection.manager.core.DefaultInjectionManager.inject(DefaultInjectionManager.java:64)
[:1.0.0-alpha-6]
at
org.jboss.ejb3.injection.InjectionInvocation.invokeTarget(InjectionInvocation.java:140)
[:1.7.19-SNAPSHOT]
at org.jboss.ejb3.injection.InjectionInvocation.invokeNext(InjectionInvocation.java:125)
[:1.7.19-SNAPSHOT]
at
org.jboss.ejb3.core.context.CurrentInvocationContextInterceptor.invoke(CurrentInvocationContextInterceptor.java:47)
[:1.7.19-SNAPSHOT]
at org.jboss.ejb3.injection.InjectionInvocation.invokeNext(InjectionInvocation.java:116)
[:1.7.19-SNAPSHOT]
at
org.jboss.aspects.currentinvocation.CurrentInvocationInterceptor.invoke(CurrentInvocationInterceptor.java:67)
[:1.0.1]
at org.jboss.ejb3.injection.InjectionInvocation.invokeNext(InjectionInvocation.java:116)
[:1.7.19-SNAPSHOT]
at org.jboss.ejb3.EJBContainer.injectBeanContext(EJBContainer.java:1363)
[:1.7.19-SNAPSHOT]
at
org.jboss.ejb3.stateful.StatefulContainer.createBeanContext(StatefulContainer.java:184)
[:1.7.19-SNAPSHOT]
at org.jboss.ejb3.stateful.StatefulContainer.create(StatefulContainer.java:136)
[:1.7.19-SNAPSHOT]
at org.jboss.ejb3.cache.simple.SimpleStatefulCache.create(SimpleStatefulCache.java:417)
[:1.7.19-SNAPSHOT]
... 15 more
--
This message is automatically generated by JIRA.
For more information on JIRA, see:
http://www.atlassian.com/software/jira