-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 
Author Message
 Post subject: Delete - one to many nullify - cache not invalidated
PostPosted: Mon Mar 21, 2011 8:39 am 
Newbie

Joined: Mon Mar 21, 2011 8:18 am
Posts: 4
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 !


Top
 Profile  
 
 Post subject: Re: Delete - one to many nullify - cache not invalidated
PostPosted: Fri Mar 25, 2011 7:28 am 
Newbie

Joined: Mon Mar 21, 2011 8:18 am
Posts: 4
Nobody has idea on what is going on this case ?

Help will be greatly appreciated :-)

Thanks


Top
 Profile  
 
 Post subject: Re: Delete - one to many nullify - cache not invalidated
PostPosted: Fri Mar 25, 2011 10:03 am 
Regular
Regular

Joined: Fri Jan 28, 2011 11:44 am
Posts: 117
Your entity is still cached in your 1st level cache ...
Try refreshing your session: Session.refresh()


Last edited by overmeulen on Fri Mar 25, 2011 10:41 am, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: Delete - one to many nullify - cache not invalidated
PostPosted: Fri Mar 25, 2011 10:07 am 
Newbie

Joined: Mon Mar 21, 2011 8:18 am
Posts: 4
Thanks for your reply.

Of course, if I manually call Session.refresh(), it works.
But why should I do it manually as Hibernate has everything in his hand to know the cache of this entity MUST be invalidated ?


Top
 Profile  
 
 Post subject: Re: Delete - one to many nullify - cache not invalidated
PostPosted: Fri Mar 25, 2011 10:33 am 
Regular
Regular

Joined: Fri Jan 28, 2011 11:44 am
Posts: 117
Take a look at this thread:

viewtopic.php?p=2404068


Top
 Profile  
 
 Post subject: Re: Delete - one to many nullify - cache not invalidated
PostPosted: Wed Mar 30, 2011 9:31 am 
Newbie

Joined: Mon Mar 21, 2011 8:18 am
Posts: 4
Sorry to reply so late, I didn't received/saw the email notification.

Anyway, thanks for your link. I think I need a deeper look on hibernate cache mechanism ;-)


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.