-->
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: object identity
PostPosted: Fri Dec 30, 2005 4:00 am 
Beginner
Beginner

Joined: Wed Aug 10, 2005 4:22 am
Posts: 24
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version: 3.0

Mapping documents:

Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:

Name and version of the database you are using:

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:

I have a unidirectional association between address and user. Association is from user to address. I query user and address in different sessions. That's why the address object that is in the user object and the address object i query alone is different.(they are not refer to the same memory location). how can i handle this problem?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 30, 2005 5:40 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
dont use different sessions if you want identity.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 30, 2005 8:20 am 
Beginner
Beginner

Joined: Wed Aug 10, 2005 4:22 am
Posts: 24
i know that for object identity i must use the same session,
but for my application it is not possible.

is there any other nice way of doing this by hibernate.

thnx...


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 30, 2005 2:10 pm 
Regular
Regular

Joined: Wed Dec 21, 2005 6:57 pm
Posts: 70
What are you trying to accomplish by having the different queries return the same address object?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 02, 2006 3:16 am 
Beginner
Beginner

Joined: Wed Aug 10, 2005 4:22 am
Posts: 24
actually in my project i have different objects (not address and user) but to make things simpler i gave user and adress example.

in the gui there is something like list all the addresses.
i get these adresses from the database. when a change made on this address object it is not reflected to the user object, because the address object that user has is different from the address object that we make changes.
so i want only one object.

do not say donot take addresses from database, take them from the user objects. there are some addresses that donot have a user. so i cant do that.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 02, 2006 3:47 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
if you cant use the same session or associate all the related objects back to one session you cannot get object identity.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 02, 2006 4:51 am 
Beginner
Beginner

Joined: Wed Aug 10, 2005 4:22 am
Posts: 24
ok i get it :)
thnx


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 02, 2006 10:15 am 
Regular
Regular

Joined: Wed Dec 21, 2005 6:57 pm
Posts: 70
You may need to use events or another mechanism to re-retrieve relevant addresses after the user is submitted.

Simplest is to have the user-change process directly update the address view

submitUser(User u) {
persistence.save(u);
AddressView.getCurrent().updateAllAddresses();
}

but the coupling in that sucks, so use the event pattern where you send to an event manager either the specific item that changed or a generic constant indicating the type of object that changed. The address part of the application can listen to that and update it's data.

Use a "coarse-grained" event (like all addresses changed) if you can get away with it. If updating all addresses is slow and/or happens very often, you can pass the changed user or address's ID around in the event so the view can be smarter about updating.


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.