Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <blockquote> <p><em>Is there a way I could add the object to the session, and it would be marked as persistent, but not call save() (that is, the INSERT will not be generated) until the very end?</em></p> </blockquote> <p>Consider re-factoring to use <code>Session.persist(Object)</code> instead of <code>Session.save(Object)</code> if you want to defer the execution of <code>INSERT</code> until the session is flushed and/or the transaction is closed.</p> <p>From section 10.2 of the <a href="http://docs.jboss.org/hibernate/orm/3.3/reference/en-US/html/objectstate.html#objectstate-makingpersistent" rel="nofollow">JBoss Hibernate Community documentation</a>:</p> <blockquote> <p>You can also use persist() instead of save(), with the semantics defined in the EJB3 early draft.</p> <ul> <li><code>persist()</code> makes a transient instance persistent. However, it does not guarantee that the identifier value will be assigned to the persistent instance immediately, the assignment might happen at flush time. <code>persist()</code> also guarantees that it will not execute an <code>INSERT</code> statement if it is called outside of transaction boundaries. This is useful in long running conversations with an extended Session/persistence context.</li> <li><code>save()</code> does guarantee to return an identifier. If an <code>INSERT</code> has to be executed to get the identifier ( e.g. "identity" generator, not "sequence"), this <code>INSERT</code> 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.</li> </ul> </blockquote> <p>Another useful reference can be found in the top-left cell of the method-to-scenario grid at the top of the "<em>Putting it All Together</em>" section of this <a href="http://blog.xebia.com/2009/03/23/jpa-implementation-patterns-saving-detached-entities/" rel="nofollow">blog article</a> that describes the behavior of <code>persist()</code> on objects that have never been persisted as follows:</p> <blockquote> <ol> <li>Object added to persistence context as new entity</li> <li>New entity inserted into database at <code>flush()</code>/<code>commit()</code></li> </ol> </blockquote>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload