开发者

Hibernate return auto-generate id of a newly inserted row

开发者 https://www.devze.com 2023-04-05 20:26 出处:网络
I\'m using HibernateTemplate to access the database in my Spring application. Is there any way/method in HibernateTemplate which returns the auto-generate id

I'm using HibernateTemplate to access the database in my Spring application. Is there any way/method in HibernateTemplate which returns the auto-generate id for my new inserted row? In my case, the auto-generate value is the primary key of my table, which is defined as auto-increment inside the dat开发者_开发问答abase.

For more info, I use saveOrUpdate() method to insert data.


When you save a object with saveOrUpdate() the objects id field will get updated with the auto generated id if it was a create operation. So you can simply retrieve the id property of the saved object to get the auto generated id.

0

精彩评论

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