| 
					
						 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. 
					
  
						
					 |