• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Query & flush

 
Sharon Adar
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Fast question:
Inside pre remove callback i've executed a EJBQL query, but no flush occurred, Why?
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Sharon Adar:
Fast question:
Inside pre remove callback i've executed a EJBQL query, but no flush occurred, Why?


You mean a JPA-QL query?

Mark
 
Sharon Adar
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yep.
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, just making sure.

In some cases a flush is not needed. Depending on the implementation of course. For instance in Hibernate there is an algorithm, I do not know it, that will determine if some of the objects that would need to be flushed have an impact on the return results of of the query. If it does have an impact, then it will flush, if not, it doesn't flush. At least that is what I have heard.

Mark
 
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper
Posts: 4968
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I go into some detail about the flush and refresh methods in a tutorial I wrote about "How Hibernate Works." Here's a little snippet from the article:

The Skinny on How Hibernate Works, and How You Can Use It


As you know, the Hibernate Session will be keeping track of all of the updates that happen to instances that are associated with it, and as you could imagine, the list of updates that may need to be committed might end up getting quite large. Using the default configuration of Hibernate, you can never be totally sure when the updates will be committed to the database; all you can be sure of is that once the transaction has been committed, the updates have happened. However, if you have some compelling reason to rush the updates, and have them sent immediately to the database, you can call the flush() method on the Hibernate Session.
FlushMode

You can override the default flushing behavior of the Hibernate Session if you so desire. To have more control over how and when Hibernate will flush the changes that the Session is marinating, you can set the Session's FlushMode. There are five flush modes, although one has been deprecated. They are:

* AUTO - the Session is typically flushed before query execution to ensure query results do not contain stale data
* ALWAYS - the Session is flushed before every query
* COMMIT - the Session is flushed when the transaction.commit() method is called
* MANUAL - the Session is only flushed when the flush() method is invoked on the Session


-Cameron McKenzie
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic