How can I get last inserted id using Hibernate

后端 未结 4 1978
醉话见心
醉话见心 2020-12-31 11:51

I want to fetch the last inserted value\'s id in Hibernate.

After search:

Long lastId = ((Long) session.createSQLQuery(\"SELECT LAST_INSERT_ID()\").         


        
4条回答
  •  悲&欢浪女
    2020-12-31 12:30

    Error is pretty clear. It's returning BigInteger and not long

    You have to assign it to a BigInteger. And get longValue() from it.

提交回复
热议问题