Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Flush session directly without HibernateTemplate; Set FlushMode to Fl…
…ushMode.MANUAL (instead of deprecated FlushMode.NEVER).
  • Loading branch information
lhotari committed Apr 25, 2012
1 parent 1dce7b5 commit a7f1377
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 19 deletions.
Expand Up @@ -60,7 +60,7 @@ public Object doInHibernate(Session session) throws HibernateException, SQLExcep
session.lock(merged, LockMode.NONE);

if (flush) {
getHibernateTemplate().flush();
session.flush();
}
return merged;
}
Expand Down
Expand Up @@ -21,12 +21,11 @@
import org.codehaus.groovy.grails.commons.GrailsApplication;
import org.codehaus.groovy.grails.commons.GrailsDomainClass;
import org.codehaus.groovy.grails.orm.hibernate.HibernateDatastore;
import org.hibernate.FlushMode;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.dao.DataAccessException;
import org.springframework.orm.hibernate3.HibernateCallback;
import org.springframework.orm.hibernate3.HibernateTemplate;

/**
* Follows the semantics of saveOrUpdate of scheduling the object for persistence when a flush occurs.
Expand Down Expand Up @@ -57,14 +56,7 @@ protected Object performSave(final Object target, final boolean flush) {
public Object doInHibernate(Session session) throws HibernateException, SQLException {
session.saveOrUpdate(target);
if (flush) {
try {
getHibernateTemplate().flush();
}
catch (DataAccessException e) {
// session should not be flushed again after a data acccess exception!
getHibernateTemplate().setFlushMode(HibernateTemplate.FLUSH_NEVER);
throw e;
}
flushSession(session);
}
return target;
}
Expand All @@ -77,17 +69,20 @@ protected Object performInsert(final Object target, final boolean shouldFlush) {
public Object doInHibernate(Session session) throws HibernateException, SQLException {
session.save(target);
if (shouldFlush) {
try {
getHibernateTemplate().flush();
}
catch (DataAccessException e) {
// session should not be flushed again after a data acccess exception!
getHibernateTemplate().setFlushMode(HibernateTemplate.FLUSH_NEVER);
throw e;
}
flushSession(session);
}
return target;
}
});
}

protected void flushSession(Session session) throws HibernateException {
try {
session.flush();
} catch (HibernateException e) {
// session should not be flushed again after a data acccess exception!
session.setFlushMode(FlushMode.MANUAL);
throw e;
}
}
}

0 comments on commit a7f1377

Please sign in to comment.