-->
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.  [ 2 posts ] 
Author Message
 Post subject: can not store parent=child, addChild only accepts 1 child
PostPosted: Fri Dec 30, 2005 3:12 pm 
Please help me with this. This is literally holding up sending our product to the client. I cannot be in a worse situation. I am sitting here a by myself and I am in trouble. This seems like an easy thing to fix, but I am so exhausted that I just can not seem to find my way out of this maze.. I need some help

I am creating a parent child relationship. There is a Master and a ContentDetail object. This addDetail code lives inside of my MasterObject. The MasterObject creates a ContentDetail object and then calls this method.

Now the thing to note here is that the this.details.add(contentDetail); only adds the first ContentDetail object but none of the other ones.

So when I go to persists this master child model. I get one Master and then first child (ContentDetail) object. None of the other ContentDetail objects. Please can someone help me out with this.

    public void addDetail(ContentDetail contentDetail) {
    logger.debug("[ContentMaster::addDetail]Entered");
    contentDetail.setContentMaster(this);
    this.details.add(contentDetail);
    logger.debug("[ContentMaster::addDetail]Exit");
    }


As a side note, and a contributing factor, the Id fields for all the ContentDetail objects being added are null, since they have not been saved to the database. This is causing my standard hibernate equals and hashcode methods to return true and 629 accordingly.

My understanding is that I am not really allowed to manual set these and that hibernate will set them when these objects are persisted, but I can not get them into the list to get persisted.. CATCH 22.. Chicken and Egg..

How do I break this deadlock.
ray


Top
  
 
 Post subject:
PostPosted: Sat Dec 31, 2005 7:52 am 
Beginner
Beginner

Joined: Sat Dec 17, 2005 1:24 pm
Posts: 42
Location: Berlin, Germany
I assume, this.details is some kind of collection, probably a HashSet? If this is the case, than Java does not add another instance to the Set, if it is equal() (according to your implementation of the equals() method of the class) to an instance already in the Set. Please note, that if you use a TreeSet (because you wanted an ordered Set you have to provide a consistent implementation of the compareTo() method, too).

For Hibernate issues around implementing correct equals() method see this text: http://www.hibernate.org/109.html.

In my personal opinion, the Hibernate generated ID, should not play any role in the implementation of an equals() method but there is a huge thread discussing this (http://forum.hibernate.org/viewtopic.php?t=928172&highlight=equals).

All the best,

René


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