Why JPA persist() does not generated auto-increment primary ID?

前端 未结 3 1977
长发绾君心
长发绾君心 2021-01-05 07:42

I\'m using JPA toplink-essential and SQL Server 2008

My goal is to get auto-increment primary key value of the data that is going t

3条回答
  •  执笔经年
    2021-01-05 08:22

    We are also using SQL Server 2008 and it never worked for me so I always execute separate query "SELECT @@IDENTY" to get the inserted id.

    The reason I found on the net was that auto id (IDENTITY) is managed by database and never fetched in Entity until unless you commit the row or manually retrieve the info from database.

提交回复
热议问题