These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Database triggers + session.save()
PostPosted: Wed Mar 16, 2005 5:30 am 
Newbie

Joined: Wed Mar 16, 2005 5:06 am
Posts: 4
Hi
I have a table in my database (oracle9) with a trigger for inserting rows: for each insert, it sets the primary key to a new value of some sequence (my_sequence).
In my hibernate mapping, i have something like this for my primary key:
Code:
...
      <id name="id" column="ID" type="long">
         <generator class="sequence">
            <param name="sequence">my_sequence</param>
         </generator>
      </id>
...


So, when calling session.save(object), the following is happening (i suppose):
hibernate gets a new sequence number, assigns it to the 'object' parameter and performs an insert... that insert is triggered by the database, so the trigger gets a new sequence number and assigns it as the new primary key of the row-to-be-inserted. Of course:
1. my sequence number is increased by two for each insert
2. session.save returns me the wrong sequence number, i.e. first the sequence number
3. the newly persisted object has the wrong primary key

My question: can i do something about it? (it is impossible to remove the trigger!).

Kind regards
Pieter Vandepitte[/code]


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.