Skip to content

Commit

Permalink
upgraded to hibernate 4.2.19.Final
Browse files Browse the repository at this point in the history
switch back to standard play save() behaviour
  • Loading branch information
pareis committed May 1, 2015
1 parent cef09c5 commit 9d6a696
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 92 deletions.
Binary file modified framework/lib/hibernate-core-4.2.19.Final.jar
Binary file not shown.
6 changes: 0 additions & 6 deletions framework/patches/hibernate-4.2.15-patch-play.README

This file was deleted.

6 changes: 6 additions & 0 deletions framework/patches/hibernate-4.2.19-patch-play.README
@@ -0,0 +1,6 @@
----
Download Hibernate 4.2.19.Final source code, apply the patch, and build with gradle (tip use export GRADLE_OPTS=-Xmx1G -XX:MaxPermSize=512m)
----

DRY RUN -> patch --dry-run -p1 -i hibernate-4.2.19-patch-play.patch
APPLY -> patch -p1 -i hibernate-4.2.19-patch-play.patch
170 changes: 85 additions & 85 deletions framework/src/play/db/jpa/HibernateInterceptor.java
@@ -1,85 +1,85 @@
//package play.db.jpa;
//
//
//import org.hibernate.CallbackException;
//import org.hibernate.EmptyInterceptor;
//import org.hibernate.collection.spi.PersistentCollection;
//import org.hibernate.type.Type;
//import java.io.Serializable;
//
//
//public class HibernateInterceptor extends EmptyInterceptor {
//
// public HibernateInterceptor() {
//
// }
// public int[] findDirty(Object o, Serializable id, Object[] arg2, Object[] arg3, String[] arg4, Type[] arg5) {
// if (o instanceof JPABase && !((JPABase) o).willBeSaved) {
// return new int[0];
// }
// return null;
// }
//
// public boolean onCollectionUpdate(Object collection, Serializable key) throws CallbackException {
// if (collection instanceof PersistentCollection) {
// Object o = ((PersistentCollection) collection).getOwner();
// if (o instanceof JPABase) {
// if (entities.get() != null) {
// return ((JPABase) o).willBeSaved || ((JPABase) entities.get()).willBeSaved;
// } else {
// return ((JPABase) o).willBeSaved;
// }
// }
// } else {
// System.out.println("HOO: Case not handled !!!");
// }
// return super.onCollectionUpdate(collection, key);
//}
//
//public boolean onCollectionRecreate(Object collection, Serializable key) throws CallbackException {
// if (collection instanceof PersistentCollection) {
// Object o = ((PersistentCollection) collection).getOwner();
// if (o instanceof JPABase) {
// if (entities.get() != null) {
// return ((JPABase) o).willBeSaved || ((JPABase) entities.get()).willBeSaved;
// } else {
// return ((JPABase) o).willBeSaved;
// }
// }
// } else {
// System.out.println("HOO: Case not handled !!!");
// }
//
// return super.onCollectionRecreate(collection, key);
//}
//
//public boolean onCollectionRemove(Object collection, Serializable key) throws CallbackException {
// if (collection instanceof PersistentCollection) {
// Object o = ((PersistentCollection) collection).getOwner();
// if (o instanceof JPABase) {
// if (entities.get() != null) {
// return ((JPABase) o).willBeSaved || ((JPABase) entities.get()).willBeSaved;
// } else {
// return ((JPABase) o).willBeSaved;
// }
// }
//} else {
// System.out.println("HOO: Case not handled !!!");
//}
//return super.onCollectionRemove(collection, key);
//}
//
//protected ThreadLocal<Object> entities = new ThreadLocal<Object>();
//
//@Override
//public boolean onSave(Object entity, Serializable id, Object[] state, String[] propertyNames, Type[] types) {
// entities.set(entity);
// return super.onSave(entity, id, state, propertyNames, types);
//}
//
//@Override
//public void afterTransactionCompletion(org.hibernate.Transaction tx) {
// entities.remove();
//}
//
//}
package play.db.jpa;


import org.hibernate.CallbackException;
import org.hibernate.EmptyInterceptor;
import org.hibernate.collection.spi.PersistentCollection;
import org.hibernate.type.Type;
import java.io.Serializable;


public class HibernateInterceptor extends EmptyInterceptor {

public HibernateInterceptor() {

}
public int[] findDirty(Object o, Serializable id, Object[] arg2, Object[] arg3, String[] arg4, Type[] arg5) {
if (o instanceof JPABase && !((JPABase) o).willBeSaved) {
return new int[0];
}
return null;
}

public boolean onCollectionUpdate(Object collection, Serializable key) throws CallbackException {
if (collection instanceof PersistentCollection) {
Object o = ((PersistentCollection) collection).getOwner();
if (o instanceof JPABase) {
if (entities.get() != null) {
return ((JPABase) o).willBeSaved || ((JPABase) entities.get()).willBeSaved;
} else {
return ((JPABase) o).willBeSaved;
}
}
} else {
System.out.println("HOO: Case not handled !!!");
}
return super.onCollectionUpdate(collection, key);
}

public boolean onCollectionRecreate(Object collection, Serializable key) throws CallbackException {
if (collection instanceof PersistentCollection) {
Object o = ((PersistentCollection) collection).getOwner();
if (o instanceof JPABase) {
if (entities.get() != null) {
return ((JPABase) o).willBeSaved || ((JPABase) entities.get()).willBeSaved;
} else {
return ((JPABase) o).willBeSaved;
}
}
} else {
System.out.println("HOO: Case not handled !!!");
}

return super.onCollectionRecreate(collection, key);
}

public boolean onCollectionRemove(Object collection, Serializable key) throws CallbackException {
if (collection instanceof PersistentCollection) {
Object o = ((PersistentCollection) collection).getOwner();
if (o instanceof JPABase) {
if (entities.get() != null) {
return ((JPABase) o).willBeSaved || ((JPABase) entities.get()).willBeSaved;
} else {
return ((JPABase) o).willBeSaved;
}
}
} else {
System.out.println("HOO: Case not handled !!!");
}
return super.onCollectionRemove(collection, key);
}

protected ThreadLocal<Object> entities = new ThreadLocal<Object>();

@Override
public boolean onSave(Object entity, Serializable id, Object[] state, String[] propertyNames, Type[] types) {
entities.set(entity);
return super.onSave(entity, id, state, propertyNames, types);
}

@Override
public void afterTransactionCompletion(org.hibernate.Transaction tx) {
entities.remove();
}

}
2 changes: 1 addition & 1 deletion framework/src/play/db/jpa/JPAPlugin.java
Expand Up @@ -199,7 +199,7 @@ public void onApplicationStart() {
Logger.error(e, "Error trying to override the hibernate classLoader (new hibernate version ???)");
}

// cfg.setInterceptor(new HibernateInterceptor());
cfg.setInterceptor(new HibernateInterceptor());

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

0 comments on commit 9d6a696

Please sign in to comment.