Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

[Hibernate] Insert multiple record in one statement

 
Marco Agostino
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone.

Today i'm using hibernate and a little issue came up.

My db has 4 tables: Locations, Events, Speakers and Attendees.
Locations to Events relationship has 0:N cardinality.
Events to Speakers/Attendees relationship has 0:N cardinality.

I mapped all these tables with pojo obj having a set listing all my children.

This is what i'm trying to do:


This snippet throws a org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing: xxx.hib.test.Event

Is there a way to do something like that? What should i do?
 
Emanuel Kadziela
Ranch Hand
Posts: 187
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First, it's hard to help you with so little code listed.

It does, however, seem that you need to either cascade or persist the child before the parent. The location has a set of events, right? Well, you are creating a new event (unpersisted) and adding it to an existing (persisted) location and trying to save/update the location with the reference to the event. That will not work. Either persist the event, or cascade the persistence from the parent (location) to the child (event).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic