title: Hibernate, PostgreSQL : Could not extract resultset, SQLState 25P02
body: <p>I am working on one of our test-servers and getting an error from the hibernate when I am trying to call a method, where I get the Person object by its username. What am I doing wrong?</p>
  
  <p>Error log :</p>
  
  <pre><code>WARN : org.hibernate.engine.jdbc.spi.SqlExceptionHelper - SQL Error: 0, SQLState: 25P02
  ERROR: org.hibernate.engine.jdbc.spi.SqlExceptionHelper - ERROR: current transaction is aborted, commands ignored until end of transaction block
  WARN : org.hibernate.engine.jdbc.spi.SqlExceptionHelper - SQL Error: 0, SQLState: 25P02
  ERROR: org.hibernate.engine.jdbc.spi.SqlExceptionHelper - ERROR: current transaction is aborted, commands ignored until end of transaction block
  org.hibernate.exception.GenericJDBCException: could not extract ResultSet
          at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:54)
          at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:126)
          at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:112)
          at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:91)
          at org.hibernate.loader.Loader.getResultSet(Loader.java:2066)
          at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1863)
          at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1839)
          at org.hibernate.loader.Loader.doQuery(Loader.java:910)
          at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:355)
          at org.hibernate.loader.Loader.doList(Loader.java:2554)
          at org.hibernate.loader.Loader.doList(Loader.java:2540)
          at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2370)
          at org.hibernate.loader.Loader.list(Loader.java:2365)
          at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:497)
          at org.hibernate.hql.internal.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:387)
          at org.hibernate.engine.query.spi.HQLQueryPlan.performList(HQLQueryPlan.java:236)
          at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1300)
          at org.hibernate.internal.QueryImpl.list(QueryImpl.java:103)
          at org.hibernate.internal.AbstractQueryImpl.uniqueResult(AbstractQueryImpl.java:966)
          at com.myproject.spring.dao.PersonDAOImpl.findPersonByUsername(PersonDAOImpl.java:118)
  Caused by: org.postgresql.util.PSQLException: ERROR: current transaction is aborted, commands ignored until end of transaction block
          at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2198)
          at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1927)
          at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:255)
          at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:561)
          at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:419)
          at org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2Statement.java:304)
          at org.apache.commons.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:96)
          at org.apache.commons.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:96)
          at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:82)
  </code></pre>
  
  <p>PersonDAOImpl :</p>
  
  <pre><code> @Override
      @Transactional
      public Person findPersonByUsername(String username) {
          Session session = this.sessionFactory.getCurrentSession();
          Query query = session.createQuery("from Person as p where p.username=:username");
          query.setParameter("username", username);
          try {
              return (Person) query.uniqueResult();
          } catch (Exception e) {
              e.printStackTrace();
              return null;
          }
      }
  </code></pre>
  
  <p>The database is there, what am I doing wrong? Thank you. </p>
  
  <p><em>Update</em> This error always follows the above one :</p>
  
  <pre><code>WARN : org.hibernate.engine.jdbc.spi.SqlExceptionHelper - SQL Error: 0, SQLState: 25006
  ERROR: org.hibernate.engine.jdbc.spi.SqlExceptionHelper - ERROR: cannot execute nextval() in a read-only transaction
  org.hibernate.exception.GenericJDBCException: could not extract ResultSet
          at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:54)
          at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:126)
          at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:112)
          at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:91)
          at org.hibernate.id.SequenceGenerator.generateHolder(SequenceGenerator.java:122)
          at org.hibernate.id.SequenceHiLoGenerator$1.getNextValue(SequenceHiLoGenerator.java:81)
          at org.hibernate.id.enhanced.LegacyHiLoAlgorithmOptimizer.generate(LegacyHiLoAlgorithmOptimizer.java:77)
          at org.hibernate.id.SequenceHiLoGenerator.generate(SequenceHiLoGenerator.java:78)
          at org.hibernate.event.internal.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:118)
          at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:209)
          at org.hibernate.event.internal.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:55)
          at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:194)
          at org.hibernate.event.internal.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:49)
          at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:90)
          at org.hibernate.internal.SessionImpl.fireSave(SessionImpl.java:715)
          at org.hibernate.internal.SessionImpl.save(SessionImpl.java:707)
          at org.hibernate.internal.SessionImpl.save(SessionImpl.java:702)
  </code></pre>