Forums Register Login

[Hibernate] Insert multiple record in one statement

+Pie Number of slices to send: Send
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?
+Pie Number of slices to send: Send
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).
What's brown and sticky? ... a stick. Or a tiny ad.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 3347 times.
Similar Threads
lazily loading collection
Lazy loading not working as expected
SQLGrammarException: could not get next sequence value
Please explain me the hibernate generated sql queries in console
update while doing save in hibernate
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 04:43:30.