Uploaded image for project: 'z - Hibernate 2'
  1. HB-1219

Hibernate doesn't respect hibernate.default_schema when using a sequence generator and PostgreSQL

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Duplicate
    • Affects Version/s: 2.1.6
    • Fix Version/s: None
    • Component/s: core
    • Labels:
      None
    • Environment:
      Hibernate 2.1.6, PostgreSQL 7.4.1, Java 1.4.2_03 (Mac OS X)
    • Bug Testcase Reminder (view):

      Bug reports should generally be accompanied by a test case!

    • Last commented by a user?:
      true

      Description

      When you specify a default_scheme in the hibernate.cfg.xml the sequence generator doesn't respect the default_schema. Instead it uses the sequence in the "public" schema which is what PostgreSQL's schema search defaults to.

      Here is the generated SQL from when public.items_id_sequence exists:

      Hibernate: select nextval ('items_id_sequence')
      Hibernate: insert into beta2.items (name, id) values (?, ?)

      Note that the first line doens't specify a schema.

      Here is the generated SQL and following log lines when public.items_id_sequence doesn't exists:

      Hibernate: select nextval ('items_id_sequence')
      Sep 10, 2004 12:07:45 PM net.sf.hibernate.util.JDBCExceptionReporter logExceptions
      WARNING: SQL Error: 0, SQLState: 42P01
      Sep 10, 2004 12:07:45 PM net.sf.hibernate.util.JDBCExceptionReporter logExceptions
      SEVERE: ERROR: relation "items_id_sequence" does not exist

      Sep 10, 2004 12:07:45 PM net.sf.hibernate.util.JDBCExceptionReporter logExceptions
      WARNING: SQL Error: 0, SQLState: 42P01
      Sep 10, 2004 12:07:45 PM net.sf.hibernate.util.JDBCExceptionReporter logExceptions
      SEVERE: ERROR: relation "items_id_sequence" does not exist

      Sep 10, 2004 12:07:45 PM net.sf.hibernate.JDBCException <init>
      SEVERE: Could not save object
      org.postgresql.util.PSQLException: ERROR: relation "items_id_sequence" does not exist

      at org.postgresql.util.PSQLException.parseServerError(PSQLException.java:139)
      at org.postgresql.core.QueryExecutor.executeV3(QueryExecutor.java:154)
      at org.postgresql.core.QueryExecutor.execute(QueryExecutor.java:101)
      at org.postgresql.core.QueryExecutor.execute(QueryExecutor.java:43)
      at org.postgresql.jdbc1.AbstractJdbc1Statement.execute(AbstractJdbc1Statement.java:515)
      at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:50)
      at org.postgresql.jdbc1.AbstractJdbc1Statement.executeQuery(AbstractJdbc1Statement.java:231)
      at net.sf.hibernate.id.SequenceGenerator.generate(SequenceGenerator.java:69)
      at net.sf.hibernate.impl.SessionImpl.saveWithGeneratedIdentifier(SessionImpl.java:765)
      at net.sf.hibernate.impl.SessionImpl.save(SessionImpl.java:738)
      at net.sf.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:1388)
      at test.Something.main(Something.java:24)
      Exception in thread "main" net.sf.hibernate.JDBCException: Could not save object
      at net.sf.hibernate.impl.SessionImpl.saveWithGeneratedIdentifier(SessionImpl.java:783)
      at net.sf.hibernate.impl.SessionImpl.save(SessionImpl.java:738)
      at net.sf.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:1388)
      at test.Something.main(Something.java:24)
      Caused by: org.postgresql.util.PSQLException: ERROR: relation "items_id_sequence" does not exist

      at org.postgresql.util.PSQLException.parseServerError(PSQLException.java:139)
      at org.postgresql.core.QueryExecutor.executeV3(QueryExecutor.java:154)
      at org.postgresql.core.QueryExecutor.execute(QueryExecutor.java:101)
      at org.postgresql.core.QueryExecutor.execute(QueryExecutor.java:43)
      at org.postgresql.jdbc1.AbstractJdbc1Statement.execute(AbstractJdbc1Statement.java:515)
      at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:50)
      at org.postgresql.jdbc1.AbstractJdbc1Statement.executeQuery(AbstractJdbc1Statement.java:231)
      at net.sf.hibernate.id.SequenceGenerator.generate(SequenceGenerator.java:69)
      at net.sf.hibernate.impl.SessionImpl.saveWithGeneratedIdentifier(SessionImpl.java:765)
      ... 3 more

      After some debugging I found that the params passed into net.sf.hibernate.id.SequenceGenerator.configure(...) do not contain a property under the "schema" key, which seems to be why SequenceGenerator.generate(..) doesn't know about the schema.

        Attachments

          Activity

            People

            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Stride room