javax.transaction.RollbackException

Transaction marked for rollback. No useful information, no reason WHY it's marked for rollback. An alternative way to achieve that useless error message would be: tx.begin(); Thing t = em.find(Thing.class,thingId); t.changeField("new value"); em.persist(new SubThing(t); tx.commit(); What I gather is that for some reason it doesn't like it when the following conditions happen to Entity e within a transaction: 1) e has a field which is modified 2) e has a collection of other entities which gains a new entity (perhaps when one is modified too?) 3) the entity of which there is a collection within e has a reference to e It's totally fine if you only change the field, or only add the entity to the collection. Another question, are there known differences when using JPA with hibernate as the provider within Glassfish? All the tutorials I've read, and the Manning Java Persistence with Hibernate book use the following to get a reference to an EntityManager: EntityManagerFactory emf = Persistence.createEntityManagerFactory("nameOfPersistenceUnit"); EntityManager em = emf.createEntityManager(); But from the very beginning of my new project (using Hibernate as a JPA provider in Glassfish) that threw an exception every time I tried it. They also all get a hold of a transaction with: EntityTransaction tx = em.getTransaction(); tx.begin(); But every time I've tried that, I get an exception saying: java.lang.IllegalStateException: A JTA EntityManager cannot use getTransaction()

Samebug tips0

There are no available Samebug tips for this exception. If you know how to solve this issue, help other users by writing a short tip.

Don't give up yet. Paste your full stack trace to get a solution.

Solutions on the web533

  • via Oracle Community by rwillie6, 11 months ago
    "); em.persist(new SubThing(t); tx.commit(); What I gather is that for some reason it doesn't like it when the following conditions happen to Entity e within a transaction: 1) e has a field which is modified 2) e has a collection of other entities which gains
  • via Oracle Community by Bogumil Laska, 1 year ago
    parent session's. The object was never registered in this UnitOfWork, but read from the parent session and related to an object registered in the UnitOfWork. Ensure that you are correctly registering your objects. If you are still having problems, you can
  • via Oracle Community by 555964, 1 month ago
    Timed out and at the same time when I try to delete the existing Groups/services in ESB I am getting the same error. Can you please help me. Thanks Rao. Error: An unhandled exception has been thrown in the ESB system. The exception reported is: "javax.transaction.RollbackException: Timed out
  • Stack trace

    • javax.transaction.RollbackException: Transaction marked for rollback. No useful information, no reason WHY it's marked for rollback. An alternative way to achieve that useless error message would be: tx.begin(); Thing t = em.find(Thing.class,thingId); t.changeField("new value"); em.persist(new SubThing(t); tx.commit(); What I gather is that for some reason it doesn't like it when the following conditions happen to Entity e within a transaction: 1) e has a field which is modified 2) e has a collection of other entities which gains a new entity (perhaps when one is modified too?) 3) the entity of which there is a collection within e has a reference to e It's totally fine if you only change the field, or only add the entity to the collection. Another question, are there known differences when using JPA with hibernate as the provider within Glassfish? All the tutorials I've read, and the Manning Java Persistence with Hibernate book use the following to get a reference to an EntityManager: EntityManagerFactory emf = Persistence.createEntityManagerFactory("nameOfPersistenceUnit"); EntityManager em = emf.createEntityManager(); But from the very beginning of my new project (using Hibernate as a JPA provider in Glassfish) that threw an exception every time I tried it. They also all get a hold of a transaction with: EntityTransaction tx = em.getTransaction(); tx.begin(); But every time I've tried that, I get an exception saying: java.lang.IllegalStateException: A JTA EntityManager cannot use getTransaction() at org.hibernate.ejb.AbstractEntityManagerImpl.getTransaction(AbstractEntityManagerImpl.java:317) at com.sun.enterprise.util.EntityManagerWrapper.getTransaction(EntityManagerWrapper.java:565) at com.stag.servlet.AdminServlet.doPost(AdminServlet.java:156) at javax.servlet.http.HttpServlet.service(HttpServlet.java:738) at javax.servlet.http.HttpServlet.service(HttpServlet.java:831) at org.apache.catalina.core.ApplicationFilterChain.servletService(ApplicationFilterChain.java:411) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:290) at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:271) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:202) at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:632) at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:577) at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:94) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:206) at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:632) at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:577) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:571) at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1080) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:150) at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:632) at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:577) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:571) at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1080) at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:270) at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.invokeAdapter(DefaultProcessorTask.java:637) at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.doProcess(DefaultProcessorTask.java:568) at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.process(DefaultProcessorTask.java:813) at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.executeProcessorTask(DefaultReadTask.java:339) at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.doTask(DefaultReadTask.java:261) at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.doTask(DefaultReadTask.java:212) at com.sun.enterprise.web.connector.grizzly.TaskBase.run(TaskBase.java:265) at com.sun.enterprise.web.connector.grizzly.ssl.SSLWorkerThread.run(SSLWorkerThread.java:106)

    Write tip

    You have a different solution? A short tip here would help you and many other users who saw this issue last week.

    Users with the same issue

    You’re the first here who have seen this exception.