After some debugging of the Hibernate code, I've found something that does not look normal:
IdentifierBag.preInsert() uses the
identifiers map to check if it contains integers it generates as keys. I deducted from this method that the identifiers map should contains Integers as keys and Long as value (at least in my case).
At some point, when the
preInsert method is called the
identifiers map contains Field entities (my own class) as key and null as value.
Looks like something went wrong; since the map does not contain already generated identifiers, it regenerates them and then re-inserts objects.
The only method I found which is not inserting itergers as keys in the map is this contructor:
Code:
public IdentifierBag(SessionImplementor session, CollectionPersister persister, Serializable disassembled, Object owner)
I tried to replace lines 68 to 71 with:
Code:
identifiers.put(
new Integer(j++),
value
);
and insertion then worked fine but this broke deletion:
Code:
java.lang.ClassCastException
at net.sf.hibernate.type.LongType.set(LongType.java:32)
at net.sf.hibernate.type.NullableType.nullSafeSet(NullableType.java:48)
at net.sf.hibernate.type.NullableType.nullSafeSet(NullableType.java:35)
at net.sf.hibernate.collection.AbstractCollectionPersister.writeRowSelect(AbstractCollectionPersister.java:404)
at net.sf.hibernate.collection.AbstractCollectionPersister.deleteRows(AbstractCollectionPersister.java:579)
at net.sf.hibernate.impl.ScheduledCollectionUpdate.execute(ScheduledCollectionUpdate.java:47)
at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2308)
at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2264)
at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2187)
...
Gavin, do you have any hint on this ?