-
1. Re: flushmode=MANUAL and session.insert() problem
superfis Feb 3, 2009 12:18 PM (in response to superfis)I mean ofcourse session.save() not session.insert()... sorry
Saving part of code looks like:
public String saveNewItem( ) { PageLanguage pl = new PageLanguage( ); ... // setting properties of pl session.save( pl ); return null; }
and is executed as action from ajax4jsf commandButton
-
2. Re: flushmode=MANUAL and session.insert() problem
stefanotravelli Feb 3, 2009 2:34 PM (in response to superfis)I guess you are working with mysql and autoincrement id.
In such a case, use persist() instead of save().
persist() makes a transient instance persistent. However, it doesn't guarantee that the identifier value will be assigned to the persistent instance immediately, the assignment might happen at flush time. persist() also guarantees that it will not execute an INSERT statement if it is called outside of transaction boundaries. This is useful in long-running conversations with an extended Session/persistence context.
save() does guarantee to return an identifier. If an INSERT has to be executed to get the identifier ( e.g.
identity
generator, notsequence
), this INSERT happens immediately, no matter if you are inside or outside of a transaction. This is problematic in a long-running conversation with an extended Session/persistence context. -
3. Re: flushmode=MANUAL and session.insert() problem
superfis Feb 4, 2009 12:02 PM (in response to superfis)Thank you Stefano for you suggestion. It look reasonably. You are right that I'm using mysql with autoincrement.
I've made changes to have session.persist() instead of session.save() according to your suggestion but still something was wrong and database operations was appearing immediately before session.flush(). I know that it's my mistake somewhere in configuration or so.
I decided to switch to postgres and all this probles dissapeared - it's working exactly as I expected and all dabatase changes are visible after session.flush()
Once again, thanks! I'll try to use mysql but now I'm more comfortable working with postgres.
Slawek
-
4. Re: flushmode=MANUAL and session.insert() problem
christian.bauer Feb 4, 2009 12:37 PM (in response to superfis)Always use a sequence, or sequence-like generator, if you can (even on MySQL):
http://in.relation.to/Bloggers/New323HibernateIdentifierGenerators
-
5. Re: flushmode=MANUAL and session.insert() problem
superfis Feb 4, 2009 8:43 PM (in response to superfis)Thanks. I'll try to use sequence (described in blog) with mysql.