Meaningless Drivel is fun!*
The moose likes Object Relational Mapping and the fly likes Hibernate 3.3.2 not flushing inserts before selects Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Hibernate 3.3.2 not flushing inserts before selects" Watch "Hibernate 3.3.2 not flushing inserts before selects" New topic
Author

Hibernate 3.3.2 not flushing inserts before selects

Daniel Matthews
Greenhorn

Joined: Aug 17, 2009
Posts: 7
Hi,

I am experiencing a strange problem when using Hibernate EntityManager 3.3.2 where insert queries are not flushed to the db before attempting a select query within the same transaction.

I am using container-managed JTA transactions (Weblogic) and Oracle 9i.

This is quite confusing as i have a unit test that exercises this code but it auto flushes prior to executing the select. This is also running in JTA transaction (JOTM) against HSQLDB.

I would appreciate it if any one could clarify what is supposed to happen in this scenario?
Emanuel Kadziela
Ranch Hand

Joined: Mar 24, 2005
Posts: 186
Do you get any error message? What does your code look like?
Daniel Matthews
Greenhorn

Joined: Aug 17, 2009
Posts: 7
Hi,

I do not get any error messages as the entity manager is flushed when the transaction commits. In short here is my code

all within a single transaction:



I would have thought that when an Invoice is persisted the subsequent call to findExistingInvoice for the next charge would flush the entity manager as it does in my unit test.

I can work around this problem by changing my transaction boundaries, i.e. each iteration is separate unit of work but i would like to know what hibernate is doing.
stanislav bashkirtsev
Ranch Hand

Joined: Aug 17, 2009
Posts: 75
You didn't show the code that saves objects.
Eduardo Bueno
Ranch Hand

Joined: Jun 04, 2009
Posts: 155
You could try closing the session instead of flushing.
Daniel Matthews
Greenhorn

Joined: Aug 17, 2009
Posts: 7
This is not really an option the session/entity manager is container managed (or has the semantics of) via Springs orm stuff. Anyhow I have changed my transaction boundaries now to get around this.

Thanks
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Hibernate 3.3.2 not flushing inserts before selects
 
Similar Threads
Declarative Transactions in Hibernate
JTA Transaction
Injecting a session bean into an application bean
Make hibernate use JTA transaction in WAS 5.1
Double transaction counts when using Hibernate Statistics