Hibernate auto-increment field for multiple databases

I have a Java object with a field that should be automatically added to the database. This field is not a primary key, but simply a field that needs to be automatically increased.

My question is, what value do I need to set for this field in my Java object before doing session.save (Object)? Should I set it to NULL?

How to display this field in Hibernate? This is what I have but not working:

<property name="reportNum" type="java.lang.Long">
 <column name="REPORTNUM"/>
 <generator class="increment"/>
</property>

Also, the application must support both MySQL and SQL Server.

Thanks in advance.

+5
source share
2 answers

insert = false, update = false. , @Generated , insert/update = false .

+1

<generator> id. .

1

, ( 1 ) (. 5.6. ):

<property name="reportNum" type="java.lang.Long" generated="insert">
  <column name="REPORTNUM"/>
</property>

Hibernate, insert ( Hibernate ).

2

. , . .

1 : , non pk.

0

All Articles