File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hibernate 3.3.2 not flushing inserts before selects

 
Daniel Matthews
Greenhorn
Posts: 7
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 187
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you get any error message? What does your code look like?
 
Daniel Matthews
Greenhorn
Posts: 7
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 75
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You didn't show the code that saves objects.
 
Eduardo Bueno
Ranch Hand
Posts: 155
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could try closing the session instead of flushing.
 
Daniel Matthews
Greenhorn
Posts: 7
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic