-->
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.  [ 4 posts ] 
Author Message
 Post subject: help please
PostPosted: Wed Oct 12, 2005 7:25 am 
Beginner
Beginner

Joined: Wed Aug 10, 2005 4:22 am
Posts: 24
hi

I have Person and Address classes. There is a unidirectional relationship between these two. When my program starts i get all the persons from the database (also all the addresses that have a relation with some person) but some other time i need all the addersses, so i check all the addresses form database.

since i get them in different sessions

person1.getAddress() == address1

returns false. but i want them to be equal.

I think that if i make address class eternal in the ehcache when one query wants an address the ehcache always return the same object.

so there will be only one copy of the address class in the memory.

the question is am i right???

if not then is there any other way of doing this using hibernate?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 12, 2005 8:30 am 
Newbie

Joined: Wed Oct 12, 2005 4:54 am
Posts: 9
You might try to override the .equals(..) method with a check of all attributes of the objects ?! So a statement as person1.getAddress().equals(address1) would be evaluated to true.

regards


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 12, 2005 10:59 am 
Beginner
Beginner

Joined: Mon Sep 27, 2004 4:28 pm
Posts: 44
You'll definitely need to override equals() (and don't forget hashcode!)..

The problem with assuming ehcache will return the same instance is that there are definitely cases where it won't. For instance, if your first session get's the entity from the cache, and your second session does a query which refreshes the cached instance, then you'll have to different instances for sure.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 13, 2005 2:03 am 
Beginner
Beginner

Joined: Wed Aug 10, 2005 4:22 am
Posts: 24
thanks for help but equals and hashcode doesnot solve my problem.
because what i want is there must be only one copy of an entity in the ram. i think there is no way of doing this by hibernate.


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