Hi All,
I am receiving the following error and I'm not sure why.
The code I am using is as follows;
Code:
@Stateless(name = "accountService")
public class AccountService implements AccountServiceLocal
{
@PersistenceUnit(unitName = "persistence-local")
EntityManagerFactory emf;
@Override
@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
public void runAccount()
{
EntityManager manager = emf.createEntityManager();
try
{
manager.getTransaction().begin();
AccountNumber number = new AccountNumber();
number.setAccountNumber(45987564);
Card card = new Card();
card.setAccountNumber(number);
manager.persist(card);
manager.getTransaction().commit();
}
finally
{
manager.close();
}
}
}
My persistence.xml file is as follows;
Code:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="persistence-local" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<non-jta-data-source>jdbc/sample</non-jta-data-source>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<shared-cache-mode>NONE</shared-cache-mode>
<properties>
<property name="hibernate.hbm2ddl.auto" value="create-drop"/>
<property name="hibernate.dialect" value="org.hibernate.dialect.DerbyDialect"/>
<property name="hibernate.show_sql" value="true"/>
</properties>
</persistence-unit>
</persistence>
The main point is when I have the @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED) annotation on the runAccount() method I get the following Exception;
Code:
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)
......
However, if I remove the @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED) annotation (which defaults to TransactionAttributeType.REQUIRED) the method works as expected.
My problems is I don't understand why adding @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED) annotation would cause the exception as I was under the impression that a Resource-Local Entity Manager does not use JTA or container managed transactions and therefore if a container managed transaction was not present it shouldn't matter. What also adds to my confusion is in the stack trace I see a reference to a org.hibernate.engine.transaction.Isolater$JtaDelegate.delegateWork(Isolater.java:147) class which reinforces my belief that JTA is still involved in the Resource-Local transaction.
I would be very appreciative of your help and comments and let me know if I have missed something elementary here.
Thanks in advance.