aspose file tools*
The moose likes Object Relational Mapping and the fly likes Is my approach right while inserting a foreign key? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Is my approach right while inserting a foreign key?" Watch "Is my approach right while inserting a foreign key?" New topic
Author

Is my approach right while inserting a foreign key?

chaitanya karthikk
Ranch Hand

Joined: Sep 15, 2009
Posts: 800

Hi all, I am new to hibernate and started practicing from yesterday. I tried with a simple insertion, selection code. Later thought to try a foreign key insertion. This is the code I used to insert records in 2 tables which has a foreign key.

Author.hbm.xmlAuthor.javaBook.javaExample.javaThe records are being successfully inserted.

My problem starts here. Suppose I want to insert another book for the same author. I am using the following approach.
I am taking the author's id and his name, then setting the Author.java POJO class and then setting name and author of the Book.java POJO class and then executing the program. The records are being successfully inserted. The problem is I have to set all details for Author.java POJO. If am not setting author.setName(String) a NULL is being inserted.

How to add a record in the child table without having to change the record in the parent table.

Hope you all understood my problem. Can anyone please shed some light on this issue. Thank you all in advance.


Love all, trust a few, do wrong to none.
chaitanya karthikk
Ranch Hand

Joined: Sep 15, 2009
Posts: 800

Is there anyone who can guide me?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Is my approach right while inserting a foreign key?
 
Similar Threads
with Hibernate in one to many
Please help me .....Hibernate Expertise Required
How to insert using hibernate?
EJB3.0 example
StaleStateException