Java Reference
In-Depth Information
public void refresh(Object object)
throws HibernateException
public void refresh(Object object, LockMode lockMode)
throws HibernateException
Updating Entities
Hibernate automatically persists into the database changes made to persistent objects.
If a property changes on a persistent object, the associated Hibernate session will queue the
change for persistence to the database using SQL. From a developer's perspective, you do not
have to do any work to store these changes, unless you would like to force Hibernate to com-
mit all of its changes in the queue. You can also determine whether the session is dirty and
changes need to be committed. When you commit a Hibernate transaction, Hibernate will
take care of these details for you.
The
flush()
method forces Hibernate to flush the session, as follows:
public void flush() throws HibernateException
You can determine if the session is dirty with the
isDirty()
method, as follows:
public boolean isDirty() throws HibernateException
You can also instruct Hibernate to use a flushing mode for the session with the
setFlushMode()
method. The
getFlushMode()
method returns the flush mode for the current
session, as follows:
public void setFlushMode(FlushMode flushMode)
public FlushMode getFlushMode()
The possible flush modes are the following:
•
ALWAYS
: Every query flushes the session before the query is executed.
•
AUTO
: Hibernate manages the query flushing to guarantee that the data returned by a
query is up-to-date.
•
COMMIT
: Hibernate flushes the session on transaction commits.
•
NEVER
: Your application needs to manage the session flushing with the
flush()
method.
Hibernate never flushes the session itself.
By default, Hibernate uses the
AUTO
flush mode. Generally, you should use transaction
boundaries to ensure that appropriate flushing is taking place, rather than trying to “manu-
ally” flush at the appropriate times.
Search WWH ::
Custom Search