-->
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: URG-updating a parent does not generate id for the new child
PostPosted: Tue Jun 10, 2008 8:38 pm 
Beginner
Beginner

Joined: Thu Oct 25, 2007 1:21 pm
Posts: 29
Hi,

When i am trying to update a parent containing new child, hibernate is not generating an id for the new child.

Can anyone tell what this is happening? Thanks for any help.


Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 11, 2008 9:53 am 
Expert
Expert

Joined: Tue May 13, 2008 3:42 pm
Posts: 919
Location: Toronto & Ajax Ontario www.hibernatemadeeasy.com
You might want to look at the cascade type on each end of the relationship. Is this inheritance parent-child, or a one-to-many parent-child.

You may want to ensure that both sides of the relationship are being saved. Here's an example from a tutorial on mapping one to many relationships. The Team and Player scenario should be universally understandable:


http://jpa.ezhibernate.com/Javacode/learn.jsp?tutorial=18mappingonetomanyassociations


Code:
public static void main(String args[]){
    HibernateUtil.recreateDatabase();
    Session session=HibernateUtil.beginTransaction();

    Team team = new Team();
    Player p1 = new Player();
    Player p2 = new Player();

    session.save(team);
    session.save(p1);
    session.save(p2);

    team.setName("Pickering Atoms");
    p1.setNickName("Lefty");
    p1.setTeam(team);
    p2.setNickName("Blinky");
    p2.setTeam(team);
    HibernateUtil.commitTransaction();
  }


http://jpa.ezhibernate.com/Javacode/learn.jsp?tutorial=18mappingonetomanyassociations

_________________
Cameron McKenzie - Author of "Hibernate Made Easy" and "What is WebSphere?"
http://www.TheBookOnHibernate.com Check out my 'easy to follow' Hibernate & JPA Tutorials


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 11, 2008 1:43 pm 
Beginner
Beginner

Joined: Thu Oct 25, 2007 1:21 pm
Posts: 29
thanks for your reply. appreciate it.

let me try this way.

thanks a lot.


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.