Oracle:
create sequence ORDER_SEQ
start with 1
increment by 1
nomaxvalue;
Spring:
使用Spring提供的org.springframework.jdbc.support.incrementer.OracleSequenceMaxValueIncrementer:
OracleSequenceMaxValueIncrementer incr = new OracleSequenceMaxValueIncrementer(dataSource, "ORDER_SEQ");
int seq = incr.nextIntValue();
Hibernate:
<id name="id" column="ID" type="java.lang.Long">
<generator class="sequence">
<param name="sequence">ORDER_SEQ</param>
</generator>
</id>