-->
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: transactions and sessions?
PostPosted: Wed Aug 11, 2004 8:40 am 
Newbie

Joined: Thu Aug 28, 2003 7:14 am
Posts: 18
Hibernate version: 2.1

Hi.

I'm having trouble getting proper transactional semantics with Hibernate in Weblogic 7.0, and would
appreciate any help on the subject. I have a big loop which manages another component of the application
via the database and the JMS. Some of its work must be transactional - for example, sending a message
to the JMS and updating a row in the database; some must be non-transactional - for example, logging
to a database table; and some doesn't really matter.

In order to accomplish this, I use Bean-managed transactions, and delimit the transactions explicitly
with UserTransaction.begin()/commit(). The work within a transaction also happens on a separate
Hibernate session. My code looks something like this:

Session globalSession = sessionFactory.openSession();
UserTransaction trans = sessionContext.getUserTransaction(); // This is the J2EE sessionContext
for() { // big loop

// Some work with globalSession

//////////////////////////// BEGIN TRANSACTION
trans.begin();
Session localSession = sessionFactory.openSession();

// Create row A in the DB using localSession *** line X
// do other stuff in the transaction using localSession

localSession.flush();
localSession.close();
trans.commit();
//////////////////////////// END TRANSACTION

// More work with globalSession
globalSession.load(row A) //*** line Y

}


I've marked out the two relevant lines of code as line X and line Y. I create a row in the DB in line X, within
the transaction, using localSession. I flush, I commit, I close, but I don't see row A when I get to line Y.
I still don't see it even if I use read() instead of load() - but a find() using the primary key works.

Can anyone explain to me what's going on? Am I wrong to expect to see row A at line Y?

Thanks a lot.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 11, 2004 10:34 am 
Expert
Expert

Joined: Thu Jan 29, 2004 2:31 am
Posts: 362
Location: Switzerland, Bern
Well, I'm just guessing, but maybe it helps:

Is it possible that the wohle UserTransaction stuff joins an already running transaction. If this is true you might see the data after this running transaction is commited.

But why does globalSession.load(row A) not return anything? Maybe in // Some work with globalSession the session found 0 rows in A's table and still thinks it's emtpy. If this is true a globalSession.clear() should help.

Hope this guess work helps
Ernst


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.