I also got the same exception: ClassCastException.
I'm using Hibernate-Version: 3.1.2
--- description ---
I tried to implement a custom authorization check using a PreUpdate listener and tried to see which fields are changed.
I have a component field (a contained object) that is changed.
The first lines of the stacktrace looks like
Code:
Thread [http-0.0.0.0-80-Processor23] (Suspended (exception ClassCastException))
ComponentType.isModified(Object, Object, boolean[], SessionImplementor) line: 212
TypeFactory.findModified(StandardProperty[], Object[], Object[], boolean[][], boolean, SessionImplementor) line: 520
JoinedSubclassEntityPersister(AbstractEntityPersister).findModified(Object[], Object[], Object, SessionImplementor) line: 2832
CheckUpdate.onPreUpdate(PreUpdateEvent) line: 44
EntityUpdateAction.preUpdate() line: 209
...
The method isModified looks like (>>> indicates exception)
Code:
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;
Object[] currentValues = getPropertyValues( current, session );
>>> Object[] oldValues = ( Object[] ) old;
int loc = 0;
for ( int i = 0; i < currentValues.length; i++ ) {
int len = propertyTypes[i].getColumnSpan( session.getFactory() );
boolean[] subcheckable = new boolean[len];
System.arraycopy(checkable, loc, subcheckable, 0, len);
if ( propertyTypes[i].isModified( oldValues[i], currentValues[i], subcheckable, session ) ) {
return true;
}
loc += len;
}
return false;
}
And my local variables are:
Code:
this= ComponentType (id=466)
old= ValidPeriodImpl (id=471)
current= ValidPeriodImpl (id=474)
checkable= boolean[2] (id=475)
session= SessionImpl (id=476)
currentValues= Object[2] (id=484)
The componenttype contained object is the ValidPeriodImpl that is successfully transformed to an object array for the current state (currentValues) but the old state (that also is a ValidPeriodImpl) is cast to an object array and therefore causing a classcastexception.
---
I have now changed my code in my eventlistener to use findDirty instead of findModified and it seems to work better! I still get back an array of changed indexes so I think it could be used as a workaround. Maybe?
If someone has another opinion I would gladely read it.