Hi,
not sure whether this is a bug or misuse, but I have an object containing a AnyType-reference (with cascade=all) that under some circumstances may be null. If I then try to merge in an object that has content for the AnyType-reference, the merge() fails with a NullPointerException in AnyType.isModified(), when Hibernate tries to check whether the anytype-object has been updated. The problem seems to be that the "old"-value is a ObjectTypeCacheEntry with both entityname and id set to null. The last call to equals()-below then fails:
Code:
(In org.hibernate.type.AnyType:)
public boolean isModified(Object old, Object current, boolean[] checkable, SessionImplementor session)
throws HibernateException {
if (current==null) return old!=null;
if (old==null) return current!=null;
ObjectTypeCacheEntry holder = (ObjectTypeCacheEntry) old;
(*) if (holder.entityName==null) return current!=null;
boolean[] idcheckable = new boolean[checkable.length-1];
System.arraycopy(checkable, 1, idcheckable, 0, idcheckable.length);
return ( checkable[0] && !holder.entityName.equals( session.bestGuessEntityName(current) ) ) ||
identifierType.isModified(holder.id, getIdentifier(current, session), idcheckable, session);
}
I added the line marked with an (*), which seems to fix the problem. The intention of the check being something like "If the entityname is not set, but the current object is, then there probably was an update". Of course, I haven't got a clue whether the code fills the intention, or if there is a basic flaw in my design :-)
I'll run with this patch for now, but it would be good with feedback on whether its a good fix or just bad assumptions.
Code:
Code: