Java Mailing List Archive

http://www.gg3721.com/

Home » the NHibernate development list »

[NHibernate-development] problem with sequences and views,
 triggers with PostgreSQL

Richard Matsunaga

2008-05-12

Replies: Find Java Web Hosting

Author LoginPost Reply
Hello,
 
A colleague posted to the users forum (http://forum.hibernate.org/viewtopic.php?t=986679).
 
After getting the NHibernate build up and running and doing some testing, it's clear that the "lastval()" approach to retrieving the ID value of a new row will work _most_ of the time. Unfortunately, it doesn't if you have a trigger function that also updates another table. lastval() returns the value of the last updated sequence, not the original table's sequence.
 
We've been burned by this and are frantically searching for a solution. I tried replacing lastval() with currval(pg_get_serial_sequence('[table]', '[column]')), but this only works for tables, not for views. So again, an incomplete solution that doesn't work for us. Since I'm far from being a PostgreSQL expert, I'm hoping there's a more elegant and complete solution out there.
 
Our other option is to stop using the trigger, but that will obviously cause some significant changes to our code base to accomodate, I am hoping there is a way to avoid it. Regardless, I think the lastval() usage in the dialect is a booby trap awaiting the next person who stumbles upon it and it should be changed.
 
Thanks,
Richard
-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
Don't miss this year's exciting event. There's still time to save $100.
Use priority code J8TL2D2.
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
_______________________________________________
Nhibernate-development mailing list
Nhibernate-development@(protected)
https://lists.sourceforge.net/lists/listinfo/nhibernate-development
©2008 gg3721.com - Jax Systems, LLC, U.S.A.