I am using Hiberbnate 3.1.3
I have a mapping as below and when I try to insert a record into the TEST_TABLE, I get an Exception: 'Exception in thread "main" org.hibernate.exception.SQLGrammarException: could not fetch initial value for increment generator'
Code:
<class name="com.test.app.to.TestTable" table="TEST_TABLE" schema="TEST">
<id name="testId" type="long">
<column name="TEST_ID" precision="12" scale="0" />
<generator class="increment"></generator>
</id>
</class>
I have default schema set as below in the cfg.xml as I need to use tables from the OTHER_SCHEMA as well in my application.
Code:
<property name="hibernate.default_schema">OTHER_SCHEMA</property>
In the above case it seems to be a Hibernate Bug as a read using a TestTable object works fine and uses the 'TEST' schema correctly, but the '<generator class="increment"></generator>' does not use the 'TEST' schema but uses the default 'OTHER_SCHEMA' for getting the max ID. The query generated for max ID reads as below:
Code:
Hibernate: select max(TEST_ID) from OTHER_SCHEMA.TEST_TABLE
I am not able to specify a schema for the generator and it is not using the schema="TEST" attribute of the class which I would expect it to use.
How can this issue be resolved?