I have designed a table (in postgres) where 'id' column is autoincremented via its SEQUENCE entity. But when I began use hibernate I met the problem .... due creating the insert statement, it use the follow statement
INSERT INTO mytable (id, name) VALUE (0, 'blablabla')
...
but I want it make somethink like that:
INSERT INTO mytable (name) VALUE ('blablabla')
... Postgres have to generate id automatically (at least when I ran such scripts withing sql editor, it worked)
I belive it can be configured, but I don't know how...
Here is my part of my .hbm.xml:
<hibernate-mapping>
<class name="com.cse.database.bean.Category" table="category">
<id name="id" type="int">
<column name="id" />
<generator class="assigned" />
</id>
<property name="name" type="string">
<column name="name" length="100" not-null="true" unique="true" />
</property>
</class>
</hibernate-mapping>
<generator>, you're telling Hibernate how to create the ID.assignedmeans your application is doing it (which you don't want).identitymeans the database does it for you, which is what you want, but docs.jboss.org/hibernate/core/3.3/reference/en/html/… doesn't list PostgreSQL as supporting that. Maybesequenceworks with PostgreSQL? You may just be able to usenativeas well, and it'll automagically work...identitywould work for PostgreSQL, since the Hibernate docs didn't list that DB.