Lee Lifshits

Greenhorn
+ Follow
since Apr 17, 2008
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Lee Lifshits

Hello all -
I have a a table events that generates it's primary key. This table has another table (insertion_string) that associated to it with a foreign key. My DB is postgres.

<hibernate-mapping>
<class name="com.oversi.generated.generatedFiles.Events" table="events" schema="public">
<id name="eventId" type="long">
<column name="event_id" />
<generator class="sequence">
<param name="sequence">events_event_id_seq</param>
</generator>
</id>
<set name="insertionsStrings" inverse="true" cascade="all-delete-orphan" fetch="select">
<key>
<column name="event_id" not-null="true" />
</key>
<one-to-many class="com.oversi.generated.generatedFiles.InsertionsString" />
</set>



When I try to insert a new event object I get the error :

insert or update on table "insertions_string" violates foreign key constraint "insertions_string_event_id_fkey"
Detail: Key (event_id)=(0) is not present in table "events".

I think this is because hibernate try to insert to the foreign key table (insertion_string) before inserting to the events table ( the one with the primary key)
Please help me to solve this