Thread: PostgreSQL + hibernate
Hi! I have an application, consisting of Struts 1.2 + Tomcat 5.5 + Hibernate 3.1 + PostgreSQL 8.1 The application is developed on WinXP and installed on Fedora Core 4. On local machine everything works OK. Both databases are created from the same script and application is the same. But when installed on FC, I get the following exception: Hibernate: select nextval ('hibernate_sequence') Jan 30, 2006 8:21:35 PM org.hibernate.util.JDBCExceptionReporter logExceptions WARNING: SQL Error: 0, SQLState: 25P02 Jan 30, 2006 8:21:35 PM org.hibernate.util.JDBCExceptionReporter logExceptions SEVERE: ERROR: current transaction is aborted, commands ignored until end of transaction block Jan 30, 2006 8:21:35 PM Although when I'm trying to call hibernate sequence it works fine. twix=# select nextval ('public.hibernate_sequence'); nextval --------- 3 (1 row) twix=# select nextval ('hibernate_sequence'); nextval --------- 4 (1 row) The sequence was created with the following command: twix=# create sequence hibernate_sequence; CREATE SEQUENCE I don't see what the problem could be. Because of the connectivity problem could not connect to remote database with pgAdmin. But it's the question for the next post. Andrey
Hi, Are you doing this as the same user that your application uses? Maybe the application postgresql user doesn't have access to the sequence but the default user you're connecting as does. ( You're connecting as a postgresql super-user because you have a '#' in your command prompt - a regular user gets = ). Myatluk Andrey wrote: > Hi! > > I have an application, consisting of Struts 1.2 + Tomcat 5.5 + Hibernate > 3.1 + PostgreSQL 8.1 > > The application is developed on WinXP and installed on Fedora Core 4. > > On local machine everything works OK. Both databases are created from > the same script and application is the same. > > But when installed on FC, I get the following exception: > > Hibernate: select nextval ('hibernate_sequence') Jan 30, 2006 8:21:35 PM > org.hibernate.util.JDBCExceptionReporter logExceptions > WARNING: SQL Error: 0, SQLState: 25P02 > Jan 30, 2006 8:21:35 PM org.hibernate.util.JDBCExceptionReporter > logExceptions > SEVERE: ERROR: current transaction is aborted, commands ignored until > end of transaction block Jan 30, 2006 8:21:35 PM > > Although when I'm trying to call hibernate sequence it works fine.
The error you're seeing comes from before. You only see the fact that there was an error, and postgres is ignoring your queries until you roll back. I bet you have a glitch in your transaction handling code, like opening a transaction, getting an error on it, hibernate throws an error and you don't have a finally clause to roll back the transaction. HTH, Csaba. On Tue, 2006-01-31 at 08:13, Myatluk Andrey wrote: > Hi! > > I have an application, consisting of Struts 1.2 + Tomcat 5.5 + Hibernate > 3.1 + PostgreSQL 8.1 > > The application is developed on WinXP and installed on Fedora Core 4. > > On local machine everything works OK. Both databases are created from > the same script and application is the same. > > But when installed on FC, I get the following exception: > > Hibernate: select nextval ('hibernate_sequence') Jan 30, 2006 8:21:35 PM > org.hibernate.util.JDBCExceptionReporter logExceptions > WARNING: SQL Error: 0, SQLState: 25P02 > Jan 30, 2006 8:21:35 PM org.hibernate.util.JDBCExceptionReporter > logExceptions > SEVERE: ERROR: current transaction is aborted, commands ignored until > end of transaction block Jan 30, 2006 8:21:35 PM > > Although when I'm trying to call hibernate sequence it works fine. > > twix=# select nextval ('public.hibernate_sequence'); nextval > --------- > 3 > (1 row) > > twix=# select nextval ('hibernate_sequence'); nextval > --------- > 4 > (1 row) > > The sequence was created with the following command: > twix=# create sequence hibernate_sequence; CREATE SEQUENCE > > I don't see what the problem could be. > > Because of the connectivity problem could not connect to remote database > with pgAdmin. But it's the question for the next post. > > Andrey > > > > > ---------------------------(end of broadcast)--------------------------- > TIP 3: Have you checked our extensive FAQ? > > http://www.postgresql.org/docs/faq
Hi, Csaba, Here's the original Tomcat log. From this log you can see that exception is thrown in sequence code. HTTP Status 500 - type Exception report message description The server encountered an internal error () that prevented it from fulfilling this request. exception javax.servlet.ServletException: could not get next sequence value org.apache.struts.action.RequestProcessor.processException(RequestProces sor.java:523) org.apache.struts.action.RequestProcessor.processActionPerform(RequestPr ocessor.java:421) org.apache.struts.action.RequestProcessor.process(RequestProcessor.java: 224) org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196) org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432) javax.servlet.http.HttpServlet.service(HttpServlet.java:709) javax.servlet.http.HttpServlet.service(HttpServlet.java:802) root cause org.hibernate.exception.GenericJDBCException: could not get next sequence value org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQ LStateConverter.java:91) org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java :79) org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper. java:43) org.hibernate.id.SequenceGenerator.generate(SequenceGenerator.java:96) org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(Ab stractSaveEventListener.java:91) org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGenerat edOrRequestedId(DefaultSaveOrUpdateEventListener.java:186) org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequ estedId(DefaultSaveEventListener.java:33) org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransie nt(DefaultSaveOrUpdateEventListener.java:175) org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(Def aultSaveEventListener.java:27) org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate( DefaultSaveOrUpdateEventListener.java:70) org.hibernate.impl.SessionImpl.fireSave(SessionImpl.java:557) org.hibernate.impl.SessionImpl.save(SessionImpl.java:545) org.hibernate.impl.SessionImpl.save(SessionImpl.java:541) sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.jav a:39) sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessor Impl.java:25) java.lang.reflect.Method.invoke(Method.java:585) org.hibernate.context.ThreadLocalSessionContext$TransactionProtectionWra pper.invoke(ThreadLocalSessionContext.java:292) $Proxy0.save(Unknown Source) com.twix.webapp.registration.RegistrationSubmitAction.execute(Registrati onSubmitAction.java:66) org.apache.struts.action.RequestProcessor.processActionPerform(RequestPr ocessor.java:419) org.apache.struts.action.RequestProcessor.process(RequestProcessor.java: 224) org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196) org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432) javax.servlet.http.HttpServlet.service(HttpServlet.java:709) javax.servlet.http.HttpServlet.service(HttpServlet.java:802) note The full stack trace of the root cause is available in the Apache Tomcat/5.5.12 logs. Apache Tomcat/5.5.12 -----Original Message----- From: Csaba Nagy [mailto:nagy@ecircle-ag.com] Sent: Tuesday, January 31, 2006 12:44 PM To: Myatluk Andrey Cc: Postgres general mailing list Subject: Re: [GENERAL] PostgreSQL + hibernate The error you're seeing comes from before. You only see the fact that there was an error, and postgres is ignoring your queries until you roll back. I bet you have a glitch in your transaction handling code, like opening a transaction, getting an error on it, hibernate throws an error and you don't have a finally clause to roll back the transaction. HTH, Csaba. On Tue, 2006-01-31 at 08:13, Myatluk Andrey wrote: > Hi! > > I have an application, consisting of Struts 1.2 + Tomcat 5.5 + Hibernate > 3.1 + PostgreSQL 8.1 > > The application is developed on WinXP and installed on Fedora Core 4. > > On local machine everything works OK. Both databases are created from > the same script and application is the same. > > But when installed on FC, I get the following exception: > > Hibernate: select nextval ('hibernate_sequence') Jan 30, 2006 8:21:35 PM > org.hibernate.util.JDBCExceptionReporter logExceptions > WARNING: SQL Error: 0, SQLState: 25P02 > Jan 30, 2006 8:21:35 PM org.hibernate.util.JDBCExceptionReporter > logExceptions > SEVERE: ERROR: current transaction is aborted, commands ignored until > end of transaction block Jan 30, 2006 8:21:35 PM > > Although when I'm trying to call hibernate sequence it works fine. > > twix=# select nextval ('public.hibernate_sequence'); nextval > --------- > 3 > (1 row) > > twix=# select nextval ('hibernate_sequence'); nextval > --------- > 4 > (1 row) > > The sequence was created with the following command: > twix=# create sequence hibernate_sequence; CREATE SEQUENCE > > I don't see what the problem could be. > > Because of the connectivity problem could not connect to remote database > with pgAdmin. But it's the question for the next post. > > Andrey > > > > > ---------------------------(end of broadcast)--------------------------- > TIP 3: Have you checked our extensive FAQ? > > http://www.postgresql.org/docs/faq
Hi, Chris! I've set the sequence owner to my database user. It hasn't changed anything. I guess I have to connect through psql as user and then see what happens. If it fails, what could be my next step? Andrey -----Original Message----- From: Chris [mailto:dmagick@gmail.com] Sent: Tuesday, January 31, 2006 10:26 AM To: Myatluk Andrey Cc: pgsql-general@postgresql.org Subject: Re: [GENERAL] PostgreSQL + hibernate Hi, Are you doing this as the same user that your application uses? Maybe the application postgresql user doesn't have access to the sequence but the default user you're connecting as does. ( You're connecting as a postgresql super-user because you have a '#' in your command prompt - a regular user gets = ). Myatluk Andrey wrote: > Hi! > > I have an application, consisting of Struts 1.2 + Tomcat 5.5 + Hibernate > 3.1 + PostgreSQL 8.1 > > The application is developed on WinXP and installed on Fedora Core 4. > > On local machine everything works OK. Both databases are created from > the same script and application is the same. > > But when installed on FC, I get the following exception: > > Hibernate: select nextval ('hibernate_sequence') Jan 30, 2006 8:21:35 PM > org.hibernate.util.JDBCExceptionReporter logExceptions > WARNING: SQL Error: 0, SQLState: 25P02 > Jan 30, 2006 8:21:35 PM org.hibernate.util.JDBCExceptionReporter > logExceptions > SEVERE: ERROR: current transaction is aborted, commands ignored until > end of transaction block Jan 30, 2006 8:21:35 PM > > Although when I'm trying to call hibernate sequence it works fine.
Yes, the exception is in sequence code, but it is BECAUSE of a previous error, at least that's what I think based on the original mail. Check your transaction handling code... do you have finally clauses around all data access code rolling back if needed ? Just committing in the success case is not enough, it won't be executed on errors, and leaves you with an unusable connection and strange errors like this. Cheers, Csaba. On Tue, 2006-01-31 at 11:28, Myatluk Andrey wrote: > Hi, Csaba, > > Here's the original Tomcat log. From this log you can see that exception > is thrown in sequence code. > > > HTTP Status 500 - > > type Exception report > > message > > description The server encountered an internal error () that prevented > it from fulfilling this request. > > exception > > javax.servlet.ServletException: could not get next sequence value > > org.apache.struts.action.RequestProcessor.processException(RequestProces > sor.java:523) > > org.apache.struts.action.RequestProcessor.processActionPerform(RequestPr > ocessor.java:421) > > org.apache.struts.action.RequestProcessor.process(RequestProcessor.java: > 224) > > org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196) > > org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432) > javax.servlet.http.HttpServlet.service(HttpServlet.java:709) > javax.servlet.http.HttpServlet.service(HttpServlet.java:802) > > root cause > > org.hibernate.exception.GenericJDBCException: could not get next > sequence value > > org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQ > LStateConverter.java:91) > > org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java > :79) > > org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper. > java:43) > > org.hibernate.id.SequenceGenerator.generate(SequenceGenerator.java:96) > > org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(Ab > stractSaveEventListener.java:91) > > org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGenerat > edOrRequestedId(DefaultSaveOrUpdateEventListener.java:186) > > org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequ > estedId(DefaultSaveEventListener.java:33) > > org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransie > nt(DefaultSaveOrUpdateEventListener.java:175) > > org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(Def > aultSaveEventListener.java:27) > > org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate( > DefaultSaveOrUpdateEventListener.java:70) > org.hibernate.impl.SessionImpl.fireSave(SessionImpl.java:557) > org.hibernate.impl.SessionImpl.save(SessionImpl.java:545) > org.hibernate.impl.SessionImpl.save(SessionImpl.java:541) > sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) > > sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.jav > a:39) > > sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessor > Impl.java:25) > java.lang.reflect.Method.invoke(Method.java:585) > > org.hibernate.context.ThreadLocalSessionContext$TransactionProtectionWra > pper.invoke(ThreadLocalSessionContext.java:292) > $Proxy0.save(Unknown Source) > > com.twix.webapp.registration.RegistrationSubmitAction.execute(Registrati > onSubmitAction.java:66) > > org.apache.struts.action.RequestProcessor.processActionPerform(RequestPr > ocessor.java:419) > > org.apache.struts.action.RequestProcessor.process(RequestProcessor.java: > 224) > > org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196) > > org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432) > javax.servlet.http.HttpServlet.service(HttpServlet.java:709) > javax.servlet.http.HttpServlet.service(HttpServlet.java:802) > > note The full stack trace of the root cause is available in the Apache > Tomcat/5.5.12 logs. > Apache Tomcat/5.5.12 > > -----Original Message----- > From: Csaba Nagy [mailto:nagy@ecircle-ag.com] > Sent: Tuesday, January 31, 2006 12:44 PM > To: Myatluk Andrey > Cc: Postgres general mailing list > Subject: Re: [GENERAL] PostgreSQL + hibernate > > The error you're seeing comes from before. You only see the fact that > there was an error, and postgres is ignoring your queries until you roll > back. I bet you have a glitch in your transaction handling code, like > opening a transaction, getting an error on it, hibernate throws an error > and you don't have a finally clause to roll back the transaction. > > HTH, > Csaba. > > > On Tue, 2006-01-31 at 08:13, Myatluk Andrey wrote: > > Hi! > > > > I have an application, consisting of Struts 1.2 + Tomcat 5.5 + > Hibernate > > 3.1 + PostgreSQL 8.1 > > > > The application is developed on WinXP and installed on Fedora Core 4. > > > > On local machine everything works OK. Both databases are created from > > the same script and application is the same. > > > > But when installed on FC, I get the following exception: > > > > Hibernate: select nextval ('hibernate_sequence') Jan 30, 2006 8:21:35 > PM > > org.hibernate.util.JDBCExceptionReporter logExceptions > > WARNING: SQL Error: 0, SQLState: 25P02 > > Jan 30, 2006 8:21:35 PM org.hibernate.util.JDBCExceptionReporter > > logExceptions > > SEVERE: ERROR: current transaction is aborted, commands ignored until > > end of transaction block Jan 30, 2006 8:21:35 PM > > > > Although when I'm trying to call hibernate sequence it works fine. > > > > twix=# select nextval ('public.hibernate_sequence'); nextval > > --------- > > 3 > > (1 row) > > > > twix=# select nextval ('hibernate_sequence'); nextval > > --------- > > 4 > > (1 row) > > > > The sequence was created with the following command: > > twix=# create sequence hibernate_sequence; CREATE SEQUENCE > > > > I don't see what the problem could be. > > > > Because of the connectivity problem could not connect to remote > database > > with pgAdmin. But it's the question for the next post. > > > > Andrey > > > > > > > > > > ---------------------------(end of > broadcast)--------------------------- > > TIP 3: Have you checked our extensive FAQ? > > > > http://www.postgresql.org/docs/faq >
"Myatluk Andrey" <Andrey.Myatluk@bercut.ru> writes: > Hi, Chris! > > I've set the sequence owner to my database user. It hasn't changed > anything. > > I guess I have to connect through psql as user and then see what > happens. > If it fails, what could be my next step? That would depend on the error message you get. -Doug
On Tue, Jan 31, 2006 at 10:13:05AM +0300, Myatluk Andrey wrote: > SEVERE: ERROR: current transaction is aborted, commands ignored until > end of transaction block Jan 30, 2006 8:21:35 PM That error means something prior to that in the same transaction failed and you haven't issued a rollback yet. -- Jim C. Nasby, Sr. Engineering Consultant jnasby@pervasive.com Pervasive Software http://pervasive.com work: 512-231-6117 vcard: http://jim.nasby.net/pervasive.vcf cell: 512-569-9461
Hi, all! I was able to fix the problem, by dropping the sequence and recreating with the username hibernate uses. Although before that I connected to database as hibernate user and tried to call hibernate_sequence and it worked fine. Thank you! Andrey -----Original Message----- From: Chris [mailto:dmagick@gmail.com] Sent: Tuesday, January 31, 2006 10:26 AM To: Myatluk Andrey Cc: pgsql-general@postgresql.org Subject: Re: [GENERAL] PostgreSQL + hibernate Hi, Are you doing this as the same user that your application uses? Maybe the application postgresql user doesn't have access to the sequence but the default user you're connecting as does. ( You're connecting as a postgresql super-user because you have a '#' in your command prompt - a regular user gets = ). Myatluk Andrey wrote: > Hi! > > I have an application, consisting of Struts 1.2 + Tomcat 5.5 + Hibernate > 3.1 + PostgreSQL 8.1 > > The application is developed on WinXP and installed on Fedora Core 4. > > On local machine everything works OK. Both databases are created from > the same script and application is the same. > > But when installed on FC, I get the following exception: > > Hibernate: select nextval ('hibernate_sequence') Jan 30, 2006 8:21:35 PM > org.hibernate.util.JDBCExceptionReporter logExceptions > WARNING: SQL Error: 0, SQLState: 25P02 > Jan 30, 2006 8:21:35 PM org.hibernate.util.JDBCExceptionReporter > logExceptions > SEVERE: ERROR: current transaction is aborted, commands ignored until > end of transaction block Jan 30, 2006 8:21:35 PM > > Although when I'm trying to call hibernate sequence it works fine.