I have a Java object with a field that needs to be auto-incremented in the database. This field is not a primary key, just a field that needs to be auto-incremented.
My question is what value I need to set this field in my Java object before doing a session.save(Object)? Do I have to set it to NULL?
How would the Hibernate mapping look for this field? This is what I have but its not working:
<property name="reportNum" type="java.lang.Long">
<column name="REPORTNUM"/>
<generator class="increment"/>
</property>
Also the application needs to support both MySQL and SQL Server.
thanks in advance.
I would try and keep it as simple as possible and just mark the property with the insert=false, update=false attributes. I've ran into trouble before using the @Generated annotation with named queries, but insert/update=false has always worked as advertised.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With