-->
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.  [ 8 posts ] 
Author Message
 Post subject: First Level Cache
PostPosted: Fri Sep 02, 2005 1:56 am 
Newbie

Joined: Sat Jun 18, 2005 9:15 am
Posts: 8
Hi !!
If I do this:

Session s = getSession();
Country c1 = s.load(Country.class, new Integer(1));
Country c2 = s.load(Country.class, new Integer(1));

c1 and c2 will be the same instance (c1 == c2, I supose session is getting the instance from it's first-level cache). Is there a way to get different instances ?

Thanks !


Top
 Profile  
 
 Post subject: I think no
PostPosted: Fri Sep 02, 2005 3:30 am 
Newbie

Joined: Wed Aug 31, 2005 11:27 am
Posts: 2
Unless you create another session, there is no way, to my knowledge, to have a distinct java object. The fisrt level cache is help by the session.


Top
 Profile  
 
 Post subject: Re: First Level Cache
PostPosted: Fri Sep 02, 2005 3:45 am 
Beginner
Beginner

Joined: Tue Jul 19, 2005 4:03 am
Posts: 34
Location: Aberdeen, UK
I have not seen any solutions for getting two different instances when loading the same object. But on top of my head I can think of two possible workarounds:
1. You could try to close the session and reopen it before you load the second object.
2. You cold override the clone method and always do a clone when you load the objects.

Note. Even if c1 != c2, c1.equals(c2) should be true.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 02, 2005 4:01 am 
Beginner
Beginner

Joined: Thu Sep 01, 2005 7:43 am
Posts: 31
Location: León (Spain)
I too believe that closing and opening the session (or using another session) is the only way, but i can't see the point on having two different instances. Hibernate will complain if you modify each instance and save them...

Bye.

_________________
Please rate...

Expert on Hibernate errors... I've had them all... :P


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 02, 2005 8:20 am 
Newbie

Joined: Sat Jun 18, 2005 9:15 am
Posts: 8
I won't save the two objects.
I'm using long session pattern. I have a grid with objects, select one from editing, change it, cancel the action, back to past page, and then make a find all to refill the grid. When I make a find all, I get all objects, including my dirty object.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 02, 2005 8:32 am 
Expert
Expert

Joined: Mon Feb 14, 2005 12:32 pm
Posts: 609
Location: Atlanta, GA - USA
pruggia wrote:
I won't save the two objects.
I'm using long session pattern. I have a grid with objects, select one from editing, change it, cancel the action, back to past page, and then make a find all to refill the grid. When I make a find all, I get all objects, including my dirty object.


You can call session.evict(dirtyObject) before reading it again.

_________________
Preston

Please don't forget to give credit if/when you get helpful information.


Top
 Profile  
 
 Post subject: Interceptors
PostPosted: Fri Sep 02, 2005 8:37 am 
Beginner
Beginner

Joined: Tue Jul 19, 2005 4:03 am
Posts: 34
Location: Aberdeen, UK
This may be a long shot, but what about using Interceptors to clear out the dirty objects.

I haven’t used the Interceptor for this type of functionality, but you can detect dirty objects in the Interceptor, and the idea would then be to force Hibernate to reload the object.

The Interceptor documentation:
http://www.hibernate.org/hib_docs/v3/reference/en/html/events.html


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 02, 2005 9:41 am 
Newbie

Joined: Sat Jun 18, 2005 9:15 am
Posts: 8
Thanks !
One more question. How can I detect with an interceptor if an object is dirty and tell session to reload it from database ?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 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.