Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions framework/src/play/db/jpa/JPAPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import org.apache.commons.beanutils.PropertyUtils;
import org.apache.log4j.Level;
import org.hibernate.Interceptor;
import org.hibernate.ejb.Ejb3Configuration;

import play.Logger;
Expand Down Expand Up @@ -198,8 +199,18 @@ public void onApplicationStart() {
} catch (Exception e) {
Logger.error(e, "Error trying to override the hibernate classLoader (new hibernate version ???)");
}

cfg.setInterceptor(new HibernateInterceptor());

//play.db.jpa.HibernateInterceptor is a Hibernate interceptor that modifies Hibernate's behavior to support
//Play's .willBeSaved property on Entities (among other things).
//Here we allow the user to disable this interceptor. The user can set up their own interceptor using
//hibernate.ejb.interceptor.session_scoped if desired.
if (!dbConfig.getProperty("hibernate.interceptor.disabled", "false").toLowerCase().trim().equals("true"))
{
Logger.info(String.format("Loading Hibernate interceptor %s for db %s...", play.db.jpa.HibernateInterceptor.class.getCanonicalName(), dbName));
cfg.setInterceptor(new play.db.jpa.HibernateInterceptor());
} else {
Logger.info(String.format("play.db.jpa.HibernateInterceptor disabled for db %s...", dbName));
}

if (Logger.isTraceEnabled()) {
Logger.trace("Initializing JPA for %s...", dbName);
Expand Down