getTransaction « Transaction « JPA Q&A

1. before calling session.gettransaction, do I have to ensure one exists?

before calling session.gettransaction, do I have to ensure one exists? if so, how do I check if there is a current uncommitted transaction in the session?

2. When calling JPA's remove() : "A JTA EntityManager cannot use getTransaction()"

I've been using StackOverflow for a while, but this is my first question here. I am new to JPA, I created a "Role" entity, I would like to do CRUD operations ...

3. Hibernate: Whether session.get() needs session.getTransaction().commit()?

The Code is:

    Configuration conf = new Configuration();
    SessionFactory fact = conf.configure().buildSessionFactory();
    Session session = fact.getCurrentSession();

4. EJBException when calling entityManager.getTransaction()

This is probably something trivial, but I'd love some help. I get:

 javax.ejb.EJBException: java.lang.IllegalStateException: Illegal to call this method from injected, managed EntityManager 
 11:54:37,105 ERROR [STDERR] at org.jboss.ejb3.tx.Ejb3TxPolicy.handleExceptionInOurTx(
 11:54:37,105 ERROR [STDERR] ...

5. entityManager.getTransaction().rollback() detaches entities?

I have the following piece of code:

EntityManagerFactory emf = Persistence.createEntityManagerFactory("test")
EntityManager entityManager = emf.createEntityManager()
User user = entityManager.find(User.class, 0);
This throws an IllegalArgumentException on the fourth line saying "Entity not managed". If I change ...

6. Is there a difference between getTransaction().begin()/.commit() and joinTransaction() with JPA2/EclipseLink?

I'm using JPA2 with annotations and EclipseLink and I'm wondering if there is a difference between

EntityManager em = ...
// Some action
EntityManager em = PU.entityManager();
// Some action
and which one should I generally ...

7. em.getTransaction.begin() vs @Transactional

All, I have a question regarding using the @Transactional annotation vs having to wrap my EntityManager.persist(entity) inside of a EntityManager.getTransaction().begin() and then EntityManager.commit(); For instance, given the following method: Code: public class someDao { EntityManager em; @Transactional(readOnly=false) public void persist(Object entity) { ...

8. Invalid session.getTransaction()?

Why would that be easier? You call beginTransaction() to get a Transaction object and start a transaction at the same time. It does not make much sense to return null or return a Transaction object that isn't already active. The latter might have some uses, we are discussing the asymetry in the API right now. However, "null" is not an option. ...

9. getTransaction() error in the Hibernate Tutorial

Hi there, I am following the first tutorial that comes with Hibernate, I get the following error while compiling the code from file. D:\HiberExam\src\events\ cannot find symbol symbol : method getTransaction() location: interface org.hibernate.Session session.getTransaction().commit(); ^ 1 error Now I am not sure how to fix this as the code I am using is also available online. I would appreciate ...

10. Java.lang.NoSuchMethodError at session.getTransaction() call

Hi , I am making a simple demo application using JBoss and Hibernate3 Somewhere in my application i have a code like this...... ////////////////////////// session = HibernateUtil.getSessionFactory().openSession(); Transaction tx = session.getTransaction() ;//Java.lang.NoSuchMethodError ///////////////////////////////// The problem is that my application crashes at runtime at the statement Transaction tx = session.getTransaction() ; The stack trace gives following message , java.lang.NoSuchMethodError: org.hibernate.Session.getTransaction()Lorg/hibernate/Transaction; Have read ...

11. HelpError: A JTA EntityManager can not use getTransaction ()

java.lang.IllegalStateException: A JTA EntityManager cannot use getTransaction() at org.hibernate.ejb.AbstractEntityManagerImpl.getTransaction( at org.springframework.orm.jpa.DefaultJpaDialect.beginTransaction( at org.springframework.orm.jpa.vendor.HibernateJpaDialect.beginTransaction( at org.springframework.orm.jpa.JpaTransactionManager.doBegin( at at org.springframework.transaction.interceptor.TransactionAspectSupport.createTransactionIfNecessary( at org.springframework.transaction.interceptor.TransactionInterceptor.invoke( at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed( at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept( at com.aam2.mailingplatform.repository.IPDao$$EnhancerByCGLIB$$4af933d7.getAll() at ...