I'm having a problem with the Increment generator for ids. The SQL it is using to select the maximum id from a table is not including the schema name of the table (core - see the SQL at the bottom of this post). Am I missing something from the id element in the mapping file?
Hibernate version:
3.1
Mapping documents:
Excerpt from Sequence.hbm.xml
Code:
<class name="Sequence" table="sequence" schema="core">
<id name="sequenceId" type="int">
<column name="sequence_id" />
<generator class="increment" />
</id>
Code between sessionFactory.openSession() and session.close():Code:
Sequence foo = new Sequence();
foo.setString("Abcd");
session.store(foo);
And some other standard transaction stuff around that...
Full stack trace of any exception that occurs:Code:
Exception in thread "main" org.hibernate.exception.SQLGrammarException: could not fetch initial value for increment generator
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.id.IncrementGenerator.getNext(IncrementGenerator.java:107)
at org.hibernate.id.IncrementGenerator.generate(IncrementGenerator.java:44)
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:91)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:186)
at org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:33)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:175)
at org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:27)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:70)
at org.hibernate.impl.SessionImpl.fireSave(SessionImpl.java:530)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:518)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:514)
at dataaccess.EntityManager.Store(EntityManager.java:112)
at dataaccess.test.HibernateTester.testDatabaseStore(HibernateTester.java:60)
at dataaccess.test.HibernateTester.main(HibernateTester.java:44)
Caused by: org.postgresql.util.PSQLException: ERROR: relation "sequence" does not exist
at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:1512)
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1297)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:188)
at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:437)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:353)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2Statement.java:257)
at org.hibernate.id.IncrementGenerator.getNext(IncrementGenerator.java:85)
... 13 more
Name and version of the database you are using:PostgreSQL 8.1
The generated SQL (show_sql=true):Code:
select
max(sequence_id)
from
sequence
The SQL really should be
Code:
select
max(sequence_id)
from
core.sequence