From 33b00eb7a068366e0aaf1fc412d9e1046482c1ee Mon Sep 17 00:00:00 2001 From: EddyVerbruggen Date: Tue, 22 Nov 2022 10:14:04 +0100 Subject: [PATCH] When [Hibernate Envers](https://hibernate.org/orm/envers/) is triggered 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. --- framework/src/play/db/jpa/HibernateInterceptor.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/framework/src/play/db/jpa/HibernateInterceptor.java b/framework/src/play/db/jpa/HibernateInterceptor.java index dcd71f007f..ae3c285968 100644 --- a/framework/src/play/db/jpa/HibernateInterceptor.java +++ b/framework/src/play/db/jpa/HibernateInterceptor.java @@ -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) { @@ -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; @@ -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; @@ -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;