]
Chris Bonami commented on HHH-6454:
-----------------------------------
I have +/- same problem.
Most probably related to the use of TableGenerator.
See javadoc MultipleHiLoPerTableGenerator:
* A hilo <tt>IdentifierGenerator</tt> that returns a
<tt>Long</tt>, constructed using
* a hi/lo algorithm. The hi value MUST be fetched in a seperate transaction
* to the <tt>Session</tt> transaction so the generator must be able to
obtain
* a new connection and commit it. Hence this implementation may not
* be used when the user is supplying connections. In this
* case a <tt>SequenceHiLoGenerator</tt> would be a better choice (where
* supported).<br>
Stafeful, no transaction and persist entity with generatedValue for
ID : javax.transaction.InvalidTransactionException: Cannot resume foreign transaction:
null
----------------------------------------------------------------------------------------------------------------------------------------------------------------
Key: HHH-6454
URL:
http://opensource.atlassian.com/projects/hibernate/browse/HHH-6454
Project: Hibernate Core
Issue Type: Bug
Components: entity-manager
Affects Versions: 3.6.3, 3.6.5
Environment: OpenEJB 3.2.0,Java 6, Hibernate-entity-manager: 3.6.3,
hibernate-validator:4.0.2.
Reporter: pierre devreux
Here my use case :
I have
* a _Service_ entity :
{code:title=Service.java|borderStyle=solid}
@Entity
@TableGenerator(name="ServiceGenerator", pkColumnName="pk_val",
pkColumnValue= "service_id", valueColumnName="val",table=
"IDENTIFIER")
public class Service {
@Id
@GeneratedValue(generator="ServiceGenerator",
strategy=GenerationType.TABLE)
private long id;
private String name;
private String des;
public Service(){};
public Service(String name, String des) {
this.name = name;
this.des = des;
}
}
{code}
* a _ServiceSF / ServiceSFImpl_ stateful :
{code:title=ServiceSFImpl.java|borderStyle=solid}
@Stateful
@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
public class ServiceSFImpl implements ServiceSF {
@PersistenceContext(name="unit", type=PersistenceContextType.EXTENDED)
EntityManager em;
public void persist(Service s) {
em.persist(s);
}
@Remove
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public void remove() {
}
}
{code}
* a test
{code:title=Test.java|borderStyle=solid}
...
@Test
public void createServiceSF() throws NamingException {
ServiceSF sf = (ServiceSF) context.lookup("ServiceSFImplLocal");
Service s = new Service("name", desc");
sf.persist(s);
sf.remove();
}
...
{code}
When I launch it, persist method raise an exception :
_javax.transaction.InvalidTransactionException: Cannot resume foreign transaction: null_
.
After looking the code, I saw that hibernate starts a new transaction to get the
generated ID, and then resume the previous transaction. But in my case there is no
transaction, and Hibernate throw an InvalidTransactionException.
Here the complete stack trace :
{code:title=Bar.java|borderStyle=solid}
javax.ejb.EJBException: The bean encountered a non-application exception; nested
exception is:
javax.persistence.PersistenceException: org.hibernate.HibernateException: Unable to
resume previously suspended transaction
at
org.apache.openejb.core.ivm.BaseEjbProxyHandler.convertException(BaseEjbProxyHandler.java:359)
at org.apache.openejb.core.ivm.BaseEjbProxyHandler.invoke(BaseEjbProxyHandler.java:287)
at $Proxy44.persist(Unknown Source)
at
net.atos.od.td.nda.ddd.rt.jee.impl.DomainTransactionImpl.persist(DomainTransactionImpl.java:163)
at net.atos.ddd.test.LauncherTest.createService_aroundBody0(LauncherTest.java:39)
at
net.atos.ddd.test.LauncherTest.createService_aroundBody1$advice(LauncherTest.java:31)
at net.atos.ddd.test.LauncherTest.createService(LauncherTest.java:1)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
at
org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at
org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: javax.persistence.PersistenceException: org.hibernate.HibernateException:
Unable to resume previously suspended transaction
at
org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1214)
at
org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1147)
at
org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1153)
at
org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:678)
at org.apache.openejb.persistence.JtaEntityManager.persist(JtaEntityManager.java:114)
at net.atos.od.td.nda.ddd.rt.jee.impl.GatewayImpl.persist(GatewayImpl.java:39)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at
org.apache.openejb.core.interceptor.ReflectionInvocationContext$Invocation.invoke(ReflectionInvocationContext.java:162)
at
org.apache.openejb.core.interceptor.ReflectionInvocationContext.proceed(ReflectionInvocationContext.java:144)
at org.apache.openejb.monitoring.StatsInterceptor.record(StatsInterceptor.java:164)
at org.apache.openejb.monitoring.StatsInterceptor.invoke(StatsInterceptor.java:92)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at
org.apache.openejb.core.interceptor.ReflectionInvocationContext$Invocation.invoke(ReflectionInvocationContext.java:162)
at
org.apache.openejb.core.interceptor.ReflectionInvocationContext.proceed(ReflectionInvocationContext.java:144)
at
org.apache.openejb.core.interceptor.InterceptorStack.invoke(InterceptorStack.java:122)
at
org.apache.openejb.core.stateful.StatefulContainer.businessMethod(StatefulContainer.java:566)
at
org.apache.openejb.core.stateful.StatefulContainer.invoke(StatefulContainer.java:325)
at
org.apache.openejb.core.ivm.EjbObjectProxyHandler.businessMethod(EjbObjectProxyHandler.java:217)
at
org.apache.openejb.core.ivm.EjbObjectProxyHandler._invoke(EjbObjectProxyHandler.java:77)
at org.apache.openejb.core.ivm.BaseEjbProxyHandler.invoke(BaseEjbProxyHandler.java:282)
... 32 more
Caused by: org.hibernate.HibernateException: Unable to resume previously suspended
transaction
at
org.hibernate.engine.transaction.Isolater$JtaDelegate.delegateWork(Isolater.java:147)
at org.hibernate.engine.transaction.Isolater.doIsolatedWork(Isolater.java:67)
at
org.hibernate.engine.TransactionHelper.doWorkInNewTransaction(TransactionHelper.java:74)
at
org.hibernate.id.MultipleHiLoPerTableGenerator$1.getNextValue(MultipleHiLoPerTableGenerator.java:216)
at
org.hibernate.id.enhanced.OptimizerFactory$LegacyHiLoAlgorithmOptimizer.generate(OptimizerFactory.java:351)
at
org.hibernate.id.MultipleHiLoPerTableGenerator.generate(MultipleHiLoPerTableGenerator.java:213)
at
org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:121)
at
org.hibernate.ejb.event.EJB3PersistEventListener.saveWithGeneratedId(EJB3PersistEventListener.java:69)
at
org.hibernate.event.def.DefaultPersistEventListener.entityIsTransient(DefaultPersistEventListener.java:179)
at
org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:135)
at
org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:61)
at org.hibernate.impl.SessionImpl.firePersist(SessionImpl.java:808)
at org.hibernate.impl.SessionImpl.persist(SessionImpl.java:782)
at org.hibernate.impl.SessionImpl.persist(SessionImpl.java:786)
at
org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:672)
... 54 more
Caused by: javax.transaction.InvalidTransactionException: Cannot resume foreign
transaction: null
at
org.apache.geronimo.transaction.manager.TransactionManagerImpl.resume(TransactionManagerImpl.java:181)
at
org.hibernate.engine.transaction.Isolater$JtaDelegate.delegateWork(Isolater.java:138)
... 68 more
{code}
--
This message is automatically generated by JIRA.
For more information on JIRA, see: