File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Is my approach right while inserting a foreign key?

 
chaitanya karthikk
Ranch Hand
Posts: 806
Java MySQL Database Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
chaitanya karthikk
Ranch Hand
Posts: 806
Java MySQL Database Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there anyone who can guide me?
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic