Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hibernate auto increment field for multiple databases

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.

like image 555
Marquinio Avatar asked Nov 14 '22 09:11

Marquinio


1 Answers

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.

like image 141
Matt Brock Avatar answered Dec 07 '22 23:12

Matt Brock