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

前端 未结 3 1975
长发绾君心
长发绾君心 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:11

    The problem is you are using IDENTITY id generation. IDENTITY id generation cannot do preallocation as they require the INSERT to generate the id. TABLE and SEQUENCE id generation support preallocation, and I would always recommend usage of these, and never using IDENTITY because of this issue and because of performance.

    You can trigger the id to be generated when using IDENTITY id generation by calling flush().

提交回复
热议问题