Hibernate自增字段列

Oracle中没有自增的列,所以必须自己创建sequence,如下:

CREATE SEQUENCE id_sequence 
INCREMENT BY 1
START WITH 1
NOMAXVALUE
NOCYCLE
CACHE 10;

然后在hibernate中配置如下
  <id name="id" type="java.lang.Integer">
            <column name="ID" />
            <generator class="native">
            	<param name="sequence">id_sequence</param>
            </generator>
        </id>

不然就会报org.hibernate.exception.SQLGrammarException: could not get next sequence value的错误。

你可能感兴趣的:(Hibernate)