-->
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.  [ 5 posts ] 
Author Message
 Post subject: Not able to retreive correct id from a table with trigger
PostPosted: Fri Aug 15, 2008 2:44 pm 
Newbie

Joined: Fri Aug 15, 2008 2:38 pm
Posts: 2
Hi All
I am inserting data to a table which has a trigger associated with it. The trigger inserts some data to a audit trail table.
i am using the merge method to save my transient object.
But the id (primary key) that i receive after save is not from the table to which i am inserting but it is the id (primary key) of the audit trail table which is inserted by the trigger.

Do anybody know why this is hapenning like this? how can i resolve this issue?

Thanks in advance.
Naveen


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 18, 2008 10:33 am 
Newbie

Joined: Fri Apr 11, 2008 5:05 am
Posts: 8
Is the ID you get 1 below the actual row ID?

E.g. You create a new entry (via NHibernate), your object/ID is 5, but in the table its 6?

If so, then its probably down to an Insert fired trigger, which calls the sequence. Usually typical of Oracle.

If so, the solution is here:
http://jira.nhibernate.org/browse/NH-1176
but it's not been rolled into the main code base, even though its ready and waiting, it's been nearly 2 years.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 19, 2008 4:23 am 
Newbie

Joined: Fri Apr 11, 2008 5:05 am
Posts: 8
Is the ID you get 1 below the actual row ID?

E.g. You create a new entry (via NHibernate), your object/ID is 5, but in the table its 6?

If so, then its probably down to an Insert fired trigger, which calls the sequence. Usually typical of Oracle.

If so, the solution is here:
http://jira.nhibernate.org/browse/NH-1176
but it's not been rolled into the main code base, even though its ready and waiting, it's been nearly 2 years.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 19, 2008 8:22 pm 
Newbie

Joined: Fri Aug 15, 2008 2:38 pm
Posts: 2
Actually i am using ms sql server 2005.

Following is how my code looks like.
Testobject object = objectDAO.merge(transientInstance);

This line saves data to table1 which has a trigger inserting data to audit trail table table2.

When i do
System.out.println(object.getID())

I do not see the id from table 1 but instead i see id of table2.
Hope this gives more information of the problem i am facing.

Thanks in advance
Naveen


Top
 Profile  
 
 Post subject: Re: Not able to retreive correct id from a table with trigge
PostPosted: Thu Sep 04, 2008 9:24 am 
Beginner
Beginner

Joined: Thu Dec 23, 2004 5:24 am
Posts: 40
Location: Luxembourg
naveenkn1977 wrote:
Do anybody know why this is hapenning like this? how can i resolve this issue?


http://forum.hibernate.org/viewtopic.php?t=973262


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

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.