Thursday, June 07, 2007

User Postgresql SERIAL field type in Hibernate

If you meet the following exception when trying to use SERIAL type with Hibernate.

ERROR JDBCExceptionReporter:78 - ERROR: relation "hibernate_sequence" does not exist
Exception in thread "main" org.hibernate.exception.SQLGrammarException: could not get next sequence value


Tey to use the following generator setting:

<id name="id" column="id" type="java.lang.Integer">
<generator class="sequence">
<param name="sequence">account_id_seq<param>
</generator>
</id>


Ref: http://forum.hibernate.org/viewtopic.php?t=968817&highlight=postgresql+serial