• 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 ...
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
  • Mikalai Zaikin

Persisting pojo with collection attribute using Hibernate

Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, I'm having difficulties understanding how to persist a bean/pojo/class with a collection holding another pojo. How should I go about solving the following example:

I have these two entities:

and I've created a database with these tables:

Now let's say that I already have an author with a populated bibliography and I want to persist this to the database.

What I already tried was using hibernates merge by calling this method:

Like this

Unfortunately this doesn't seem to work as the foreign key author_id in books is never set (NULL).

What should I be doing different?
"Don't believe every tiny ad you see on the internet. But this one is rock solid." - George Washington
a bit of art, as a gift, the permaculture playing cards
    Bookmark Topic Watch Topic
  • New Topic