• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Is my approach right while inserting a foreign key?

 
Ranch Hand
Posts: 806
MySQL Database Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
MySQL Database Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is there anyone who can guide me?
 
reply
    Bookmark Topic Watch Topic
  • New Topic