Skip to content

Commit

Permalink
When [Hibernate Envers](https://hibernate.org/orm/envers/) is trigger…
Browse files Browse the repository at this point in the history
…ed via an `@Audited` annotation, it attempts to insert a record in a related `AUD` table. However, Play! assumes all related entities extend `JPABase`, which the `AUD` tables don't. This leads to a `ClassCastException` because `HashMap` is cast to `JPABase`. By adding a check for `JPABase` here, we can avoid this problem. This effectively also checks for 'not null' which the previous implementation did.
  • Loading branch information
EddyVerbruggen committed Nov 22, 2022
1 parent d6dae44 commit 33b00eb
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions framework/src/play/db/jpa/HibernateInterceptor.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class HibernateInterceptor extends EmptyInterceptor {
public HibernateInterceptor() {

}

@Override
public int[] findDirty(Object o, Serializable id, Object[] arg2, Object[] arg3, String[] arg4, Type[] arg5) {
if (o instanceof JPABase && !((JPABase) o).willBeSaved) {
Expand All @@ -27,7 +27,7 @@ public boolean onCollectionUpdate(Object collection, Serializable key) throws Ca
if (collection instanceof PersistentCollection) {
Object o = ((PersistentCollection) collection).getOwner();
if (o instanceof JPABase) {
if (entities.get() != null) {
if (entities.get() instanceof JPABase) {
return ((JPABase) o).willBeSaved || ((JPABase) entities.get()).willBeSaved;
} else {
return ((JPABase) o).willBeSaved;
Expand All @@ -44,7 +44,7 @@ public boolean onCollectionRecreate(Object collection, Serializable key) throws
if (collection instanceof PersistentCollection) {
Object o = ((PersistentCollection) collection).getOwner();
if (o instanceof JPABase) {
if (entities.get() != null) {
if (entities.get() instanceof JPABase) {
return ((JPABase) o).willBeSaved || ((JPABase) entities.get()).willBeSaved;
} else {
return ((JPABase) o).willBeSaved;
Expand All @@ -62,7 +62,7 @@ public boolean onCollectionRemove(Object collection, Serializable key) throws Ca
if (collection instanceof PersistentCollection) {
Object o = ((PersistentCollection) collection).getOwner();
if (o instanceof JPABase) {
if (entities.get() != null) {
if (entities.get() instanceof JPABase) {
return ((JPABase) o).willBeSaved || ((JPABase) entities.get()).willBeSaved;
} else {
return ((JPABase) o).willBeSaved;
Expand Down

0 comments on commit 33b00eb

Please sign in to comment.