-->
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.  [ 2 posts ] 
Author Message
 Post subject: Retrieving same object reference when loading from DB
PostPosted: Thu Feb 15, 2007 6:21 am 
Newbie

Joined: Thu Feb 15, 2007 6:14 am
Posts: 1
Hi there,

I'm new with Hibernate and I'm working my way through a case.
My question is about loading the object from the DB.

Code:
Bankrekening rekening2 = (Bankrekening)session.load(Bankrekening.class, 123L, LockMode.READ);
Bankrekening rekening3 = (Bankrekening)session.load(Bankrekening.class, 123L, LockMode.READ);


I'm loading the same object twice. However, the code above results in two references (rekening1 and rekening2) which refer to the same object.
I would like to have two objects (I'm aware that they are still 'equal', but they should not refer to the same object)

Can anyone help me out on this?
Thanks in advance!

Kind regards,

Chris


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 15, 2007 6:31 am 
Newbie

Joined: Thu Feb 15, 2007 5:46 am
Posts: 12
Location: Helsinki
Hibernate uses a lot of caching for objects to avoid hitting the database too often. If you need to have 2 distinct objects, you can either clone() your object or do session.evict(object1) to remove it from the cache before you load it again

-Jussi


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