Excelent. Thank you for the valuable tip.
But now I'm getting another annoying problem. I constructed my Bean with a lazzy contructor for one collection, like:
Code:
Set getUniversities() {
if (universities==null)
universities = new HashSet();
return universities
}
But I found that there is a check in the lock command that throws exception for any set that is not persistent class,even empty sets!:
reassociated object has dirty collection referenceclass net.sf.hibernate.impl.OnLockVisitorCode:
Object processCollection(Object collection, PersistentCollectionType type)
throws HibernateException {
SessionImpl session = getSession();
CollectionPersister persister = session.getCollectionPersister( type.getRole() );
if (collection==null) {
//do nothing
}
else if ( collection instanceof PersistentCollection ) {
PersistentCollection coll = (PersistentCollection) collection;
if ( coll.setCurrentSession(session) ) {
CollectionSnapshot snapshot = coll.getCollectionSnapshot();
if ( SessionImpl.isOwnerUnchanged( snapshot, persister, getKey() ) ) {
// a "detached" collection that originally belonged to the same entity
if ( snapshot.getDirty() ) {
throw new HibernateException("reassociated object has dirty collection");
}
session.reattachCollection(coll, snapshot);
}
else {
// a "detached" collection that belonged to a different entity
throw new HibernateException("reassociated object has dirty collection reference");
}
}
else {
// a collection loaded in the current session
// can not possibly be the collection belonging
// to the entity passed to update()
throw new HibernateException("reassociated object has dirty collection reference");
}
}
else {
// brand new collection
//TODO: or an array!! we can't lock objects with arrays now??
throw new HibernateException("reassociated object has dirty collection reference");
}
return null;
}
The reference pdf says in
Chapter 6. Collection Mapping:
Quote:
Collections obey the usual rules for value types: no shared references, created and deleted along with containing
entity. Due to the underlying relational model, they do not support null value semantics; Hibernate does not
distinguish between a null collection reference and an empty collection.
Well, in this case,DO Hibernate distinguish null x collection?