-->
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: Confused about FK
PostPosted: Thu Sep 02, 2004 9:36 am 
Newbie

Joined: Thu Sep 02, 2004 9:16 am
Posts: 1
Hibernate version: 2.1

Name and version of the database you are using:MySql 3.23.57

Hello,

I am new to Hibernate and a little confused over how the
relationships work. I have been reading the online docs
and the ebook 'Hibernate in Action' - very good book.

I have two objects Library and Book, Library one-to-many
Book. Each has its own PK(generated using 'native'), with Book
having the Library PK as a FK. If I create the two Objects.

//
Library l = new Library();
l.setName("Java Library");

Book b = new Book();
b.setTitle("Hibernate In Action");

l.addBook(b);

session.save(l);
//

Everything works great the objects are both saved to the
correct tables. However no value is entered into the book
tables FK field.

It is not possible to set this field before the object is saved to
the database because the Library object is only assigned its PK
when saved to the database. I thought (hoped) that hibernate
would take care of this and update the book FK accordingly - asking a lot I know.

So my question is, is this possible. I have tried all combinations of
inverse, cascade using several examples from the web and other
books with no success. Can you please help?

Many Thanks,
Alan.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 02, 2004 9:39 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Read the "Parent/Child Example" chapter in the reference documentation again and follow all steps exactly as described.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


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.