开发者

autoincrement in Hibernate

开发者 https://www.devze.com 2023-03-12 14:11 出处:网络
I have the ID of my table set to autoincrement in MySql 5.1 How do I map my Hibernatewith a开发者_运维问答utoincrements set in DBMS?

I have the ID of my table set to autoincrement in MySql 5.1

How do I map my Hibernate with a开发者_运维问答utoincrements set in DBMS?

I tried this way :

<id name="id" type="int" column="ID" >
<generator class="assigned"/>
</id>

Though it doesn't show any error, it does not add anything. Thanks in advance.


Try

<id name="id" type="int" column="ID" >
    <generator class="native"/>
</id>


you can also try

<id name="id" type="int" column="ID" >
<generator class="identity"/>
</id>

if you are using hibernate to generate ddl (using hibernate.hbm2ddl.auto property set to create or update) the system would generate scripts which would set autoincrement on the id column.

0

精彩评论

暂无评论...
验证码 换一张
取 消