-->
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: Parent/child in list with order
PostPosted: Mon Feb 12, 2007 11:23 am 
Newbie

Joined: Wed Feb 07, 2007 7:42 am
Posts: 13
Location: Spain
Hello,

I've got a problem with an association one-to-many bidirectional, Lists and save operations.

I have a typical relation Parent/Child, and I want that this relational will be bidirectional.

I want that the childs have order.

My class Parent is:

Code:
public class Parent{
..........
List<Child> childs = new ArrayList<Child>();
....
  //get and set for childs
}


And my Child class is:



Code:
public class Child{
..........
Parent parent;
....
  //get and set for parent
}



In my database, I've got two tables: Paretn(PARENT_ID, NAME,.....)
CHILD(CHILD_ID, NAME, PARENT_ID, INDEX_CHILD,......)

Where INDEX_CHILD is the order from the child.


I would like that when I create a new parent and a new childrens, and I save the parent, save the childres too:

Code:
Parent parent = new Parent();
Child child1 = new Child();
parent.addChild(child1);
Child child2 = new Child();
parent.addChild(child1);
Child child3 = new Child();
parent.addChild(child1);
Child child4 = new Child();
parent.addChild(child1);

parent.save();





Is it posible=


Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 12, 2007 1:04 pm 
Newbie

Joined: Wed Feb 07, 2007 7:42 am
Posts: 13
Location: Spain
I've solutioned the problem. I must add the target not-null in the key element:

Code:
   <list name="childs">
       <key column="PARENT_ID" [b]not-null="true"[/b]/>
      <list-index column="POSITION"/>
      <one-to-many class="Child" />
   </list>



My problem was that with XDoclet 1.2.3, the tag @hibernate.collection-key hasn't got the tag not-null.

What's your opinion about XDoclet2? Must I update the version?

Regards.


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.