Hello all,
I've problem with the hibernate cache when I try to delete an entity which have one-to-many relationship:
I've a table User which have a relation 'creator' pointing to the same table User.
My mapping is as follow:
Code:
...
<many-to-one name="creator" class="package.User" lazy="proxy" cascade="save-update, merge">
<column name="creatorId" />
</many-to-one>
<set name="createdUsers" cascade="save-update, merge" lazy="true">
<key column="creatorId" />
<one-to-many class="package.User" />
</set>
...
Lets say I've currently 2 users: creatorUser and createdUser, creatorUser is the creator of createdUser.
Now I want to delete creatorUser. Creator of createdUser must become null:
Code:
...
User creatorUser = getHibernateTemplate().get(User.class, id1);
User createdUser = getHibernateTemplate().get(User.class, id2);
getHibernateTemplate().delete(creatorUser);
//My database is ok, only 1 user, 'createdUser' with no creator
assertNotNull(createdUser.getCreator()); //Ok creator is still not null as I didn't refetch from database.
createdUser = getHibernateTemplate().get(User.class, id2); //No sql request has been sent ??!!!
[b]assertNull(createdUser.getCreator());[/b] //Crash, creator is still not null.
So, why hibernate cache hasn't been invalidated when my delete has been performed ? Is it a bug or am I missing something ?
PS: I'm using hibernate 3.6.0-FINAL with postgres
Thanks a lot for your lights !