-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: em.persist(entity) ignores transaction
PostPosted: Thu Mar 06, 2008 8:05 am 
Senior
Senior

Joined: Tue Sep 13, 2005 2:01 am
Posts: 137
Hi,

I am using JBoss 4.0.5GA and mysql 5.0 database.


in web tier:

UserTransaction userTransaction =
(UserTransaction)new InitialContext().lookup("java:comp/UserTransaction");

userTransaction.begin();


// in session bean, em is EntityManager
em.persist(entity);

From mysql console, the entity was created immediately in database(mysql).

I expected it to be created after calling

userTransaction.commit();

in web tier.


For debugging, I added the following code around em.persist(entity):

//debug
Session session = ((HibernateSession)em).getHibernateSession();
Transaction t = session.getTransaction();

t.begin();

em.persist(entity); // the enitty was created immediately in database (see from mysql console)

t.rollback();

boolean committed = t.wasCommitted(); // value is false
boolean rollback = t.wasRolledBack(); // value is false

after the rollback, the created entity did not roll back. The transaction was ignored.

Is this a bug? How to use UserTransaction with entityManager?

Thanks for any help!
Dave


Top
 Profile  
 
 Post subject: Re: em.persist(entity) ignores transaction
PostPosted: Thu Mar 06, 2008 12:27 pm 
Expert
Expert

Joined: Wed Apr 11, 2007 11:39 am
Posts: 735
Location: Montreal, QC
Configure hibernate with a JTA transaction factory and see if that changes the situation:

hibernate.transaction.factory_class = org.hibernate.transaction.JTATransactionFactory



Farzad-


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.