Saturday, December 8, 2007

When to flush session in hibernate?

I heard once an hibernate expert says that there is no need in any way to flush the hibernate session, According to this expert the hibernate knows better then the developer when to flush the session and when not, For example if the developer insert data to the DB several times and then read select the same row from the DB then Hibernate would just flush before the select statement.

However this is not true, there are cases when flush the session is mandatory.

For example consider the following case: In a method you insert some data to a DB table, then you send a JMS message (asynchronously) which invoke MDB which need to select the same data (in a different hibernate session) which was insert to the DB just before the JMS message,

In this case the data my not flush yet by the hibernate before the MDB select the same data,
In this case it is required to flush the session before sending the JMS message.

No comments:

Links

 
RSS Feeds Submission Directory