Reputation: 670
In grails we have the following config:
DataSource.groovy:
hibernate {
flush.mode="commit"
}
which prints "COMMIT" when we log it in a transactional context:
println "session=${sessionFactory.currentSession.flushMode}"
but when we create a new thread
this prints "AUTO".
New thread does seem to get the other hibernate settings, ie database, username and factory, but the currentSession doesn't take the flush.mode setting.
Can anyone advise?
Upvotes: 2
Views: 2280
Reputation: 5310
Are you using the Quartz plugin?
Quartz changes the flush mode: https://fisheye.codehaus.org/browse/~raw,r=41198/grails-plugins/grails-quartz/tags/LATEST_RELEASE/src/java/org/codehaus/groovy/grails/plugins/quartz/listeners/SessionBinderJobListener.java
public void jobToBeExecuted(JobExecutionContext context) {
Session session = SessionFactoryUtils.getSession(sessionFactory, true);
session.setFlushMode(FlushMode.AUTO);
TransactionSynchronizationManager.bindResource(sessionFactory, new SessionHolder(session));
if( LOG.isDebugEnabled()) LOG.debug("Hibernate Session is bounded to Job thread");
}
The workaround is to change the flush mode in the Job:
def sessionFactory
.
.
.
def session=SessionFactoryUtils.getSession(sessionFactory, false)
session?.setFlushMode(FlushMode.COMMIT)
Upvotes: 1