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.
|