I have a table that has a primary key and another value that is not a primary/foreign key, but is set as a not-null IDENTITY that is incremented by 1.
How do I set this up in my mappings? This is what I am currently doing (originally generated from the database schema using a tool):
Code:
<hibernate-mapping>
<class name="com.mycompay.dto.History" table="history">
<id name="historystepId" type="long">
<column name="historystep_id" />
<generator class="native" />
</id>
<property name="historyOrder" type="long">
<column name="history_order" not-null="true" unique="true" />
</property>
</class>
</hibernate-mapping>
In the above historystepId is the primary key, and historyOrder is just another column in the database that happens to be an IDENTITY. But this mapping does not work because historyOrder is not-null and passing null to a not-null property causes hibernate to throw an error when inserting.
Normally with a auto-incremented primary key you can set the id to null and have the database generate the id for you and hibernate gladly passes the generated id back to you. Is there any way to get this non-primary identity column to work in hibernate3?
(I already tried removing not-null in the historyOrder property mapping)