*
The moose likes Object Relational Mapping and the fly likes Persisting pojo with collection attribute using Hibernate Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Persisting pojo with collection attribute using Hibernate" Watch "Persisting pojo with collection attribute using Hibernate" New topic
Author

Persisting pojo with collection attribute using Hibernate

Kristofer Hindersson
Greenhorn

Joined: Jan 19, 2010
Posts: 25
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 get me started about those stupid light bulbs.
 
subject: Persisting pojo with collection attribute using Hibernate
 
Similar Threads
EJB3.0 example
Hiberante annotations
jboss 6 and persistence.xml file
I want to use indexed properties
EJB 3.0 Entity Bean