-->
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: identity equal?
PostPosted: Mon Oct 10, 2005 2:12 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.

Is secondary cache can solve this problem?
If not is there any way of handling this situation?
What is the harm of not closing a session?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 10, 2005 6:20 pm 
Beginner
Beginner

Joined: Wed Sep 21, 2005 11:52 am
Posts: 43
Check out this link on the Hibernate wiki: http://www.hibernate.org/109.html

Also look at the reference manual.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 11, 2005 3:28 am 
Senior
Senior

Joined: Thu Aug 04, 2005 4:54 am
Posts: 153
Location: Birmingham, UK
Implement equals() correctly and use

if (person.getAddress().equals(address)){
}


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 12, 2005 2:32 am 
Beginner
Beginner

Joined: Wed Aug 10, 2005 4:22 am
Posts: 24
i know this,
but what i want is there must be only one copy of the address class in the memory. i mean what i want is object identity.
is there any way of doing it by hibernate, if not i will do it manual.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 12, 2005 2:41 am 
Beginner
Beginner

Joined: Wed Aug 10, 2005 4:22 am
Posts: 24
also i have another question.

cfg.configure("hibernate.cfg.xml");
SchemaExport su = new SchemaExport(cfg);
su.setOutputFile("schema.txt");
su.create(true,true);
sf = cfg.buildSessionFactory();

when i say su.create it drops all the tables. what i want is if the tables doesnot exist than create, if they do exist then do nothing.
and last one question can we create database by hibernate?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 12, 2005 2:59 am 
Expert
Expert

Joined: Mon Jul 04, 2005 5:19 pm
Posts: 720
[quote="e120281"]when i say su.create it drops all the tables. what i want is if the tables doesnot exist than create, if they do exist then do nothing. [quote]
How far does this get you?

Code:
configuration.put("hibernate.hbm2ddl.auto", "update"); // not create-drop


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 12, 2005 4:16 am 
Beginner
Beginner

Joined: Wed Aug 10, 2005 4:22 am
Posts: 24
thanks dennis.

again the same question --> what i want is there must be only one copy of the address class in the memory. i mean what i want is object identity.
is there any way of doing it by hibernate, if not i will do it manual.


Top
 Profile  
 
 Post subject: identity equal?
PostPosted: Tue Oct 18, 2005 3:32 pm 
Regular
Regular

Joined: Fri Mar 04, 2005 1:33 pm
Posts: 65
Location: U.K.
You will need to do following:

1. Implement correct equals method in Address.java. This equals() method needs to do deep comparison i.e. it needs to check all the properties of Address object while determining if given 2 objects are same.

2. person.getAddress().equals(addressObj)

Ron
------
Dont forget to Rate !


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.