-->
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.  [ 3 posts ] 
Author Message
 Post subject: *-to-one relationships not returning consistent/unique obj.
PostPosted: Fri Apr 23, 2004 8:07 pm 
Regular
Regular

Joined: Wed Dec 31, 2003 4:26 am
Posts: 108
Location: Berkeley, CA
Given the following:
Code:
    PersistentObject parent = new PersistentObject();
    parent.setName("root");
    PersistentObject child = new PersistentObject ();
    child.setName("leaf");

    child.setParent(parent);
    parent.getChildren().add(child);

    session.save(parent);

I get 2 records in the DB as expected and everything looks great. In particular, child.getParent()==parent evaluates to true. Then,
Code:
    session.refresh(parent); // pick-up values set by triggers.
    session.refresh(child); // pick-up values set by triggers.

Now child.getParent()==parent evaluates to false! A bit surprising. So, trying a lengthier approach:

Code:
    session.evict(parent);
    session.evict(child);

    parent = session.load(PersistentObject, parent.getId());
    child = session.load(PersistentObject, child.getId());

Once again child.getParent()==parent evaluates to false! Calling get() rather than load() produces the same result.

I thought Hibernate uniques the objects. It looks like the uniqueness is not being enforced in a way that applies to *-to-one relationships.

Is this a bug? Is this related to the equals() issue that received much discussion lately?


Top
 Profile  
 
 Post subject:
PostPosted: Sat Apr 24, 2004 6:39 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Most likely a getter/setter broken or your equals implementation leading to that issue

_________________
Emmanuel


Top
 Profile  
 
 Post subject: PLEASE IGNORE THIS POST.
PostPosted: Sat Apr 24, 2004 5:06 pm 
Regular
Regular

Joined: Wed Dec 31, 2003 4:26 am
Posts: 108
Location: Berkeley, CA
The session accessor was returning a new Session on each invocation.


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