-->
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: Two level one-to-many relationship?
PostPosted: Tue Oct 28, 2003 8:46 pm 
Newbie

Joined: Fri Oct 24, 2003 8:22 pm
Posts: 3
Hi everyone.

Cass A has a one-to-many relationship with Class B. Class B also has a one-to-many relationship of Class C. That is, A can have many B while each B can also have many C.

I think I did the right things on Mapping. The problem is I don't know how to save them into the database.

SessionFactory sf = new Configuration().configure().buildSessionFactory();
Session s = sf.openSession();
Transaction t = s.beginTansaction();
A a = new A();
a.setB(new ArrayList());
s.save(a);

B b = new B();
b.setName("b");
b.setC(new ArrayList());

C c = new C();
c.setName("c");

What should I do next? I have no idea how to put b and c into database.

Thanks in advance.

_________________
Love is stronger than hate.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 29, 2003 12:11 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
Have you looked at the docs? Al this is covered pretty well there.

The typical case is to map A to B and B to C with cascading on saves and updates. Then simply build up your object graph and call save on the top-level; with the cascading, Hibernate takes care of the rest.


Top
 Profile  
 
 Post subject: Thank You
PostPosted: Wed Oct 29, 2003 2:17 pm 
Newbie

Joined: Fri Oct 24, 2003 8:22 pm
Posts: 3
Thanks for your time. I found out that I did everything correct except I set lazy="true"
That's why I cannot make it works.
Thank You!

_________________
Love is stronger than hate.


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.