-->
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.  [ 5 posts ] 
Author Message
 Post subject: Extra update when adding item to collection issue
PostPosted: Wed Mar 10, 2004 1:51 pm 
Regular
Regular

Joined: Thu Aug 28, 2003 10:54 am
Posts: 67
I have a parent-child relationship similar to the one in Chapter 9 of the docs except my collection belongs to a component of the parent. The relation is bidirectional and mapped with inverse=false. When I do the following

Code:
//parent loaded in another session
Child child = new Child();
child.setParent(parent);
parent.getComponent().getChildren().add(child)
parent.setModified(new Date());
session.update(parent);


I get the following SQL generated

1. Insert of child into database. Good, just what I wanted.
2. Update of parent. Fine, due to setModified();
3. Update of another child in the collection that has not had anything modifed. The child being updated changes as i add more children to the collection but it is always one update and not several.

I cannot explain 3. As far as i can tell there are no side effects to any of the above calls that could cause this. i have checked all the values before and after the update and they are the same.

I am using latest hibernate version with postgresql.

thank you


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 10, 2004 5:32 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
http://www.hibernate.org/155.html

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 10, 2004 5:33 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
And check you equals/hashCode implementation for the no-related-child-updated issue

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 11, 2004 6:52 am 
Regular
Regular

Joined: Thu Aug 28, 2003 10:54 am
Posts: 67
but, but , but... My set is mapped with inverse=true also lazy=true and cascade=all. The associaltion is bidirectional, I don't need it to be in the object model nut the parent_id field is not-null so as I understand things I must have the bidirectionality.

As for hashCode and equals. All my entities extend a base class DomainObject which defines the following methods

Code:
   public boolean equals(Object o) {
      if (this == o)
         return true;
      if (!(o instanceof DomainObject))
         return false;
      DomainObject d = (DomainObject) o;
      return (version == d.getVersion()) && equals(d);
   }

   private boolean equals(DomainObject d) {
      return id == null ? false : id.equals(d.getId());
   }

   public int hashCode() {
      return (id == null) ? 0 : id.hashCode();
   }


BTW, I get the same behaviour wether I have inverse=true or not.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 12, 2004 2:15 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Does id unique in you whole domain model ?

_________________
Emmanuel


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