Forums Register Login

SQL server: identity persistence exception

+Pie Number of slices to send: Send
I've a non id (key) column, a regular column that I want to defined with identity.

1. For HSQL

@Column(name = "NUMBER", columnDefinition="INTEGER GENERATED BY DEFAULT AS IDENTITY (start with 1)")

is OK

2. When I switch to Microsoft SQL server


When JPA persist, I got below exception.

Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: Cannot insert explicit value for identity column in table 'CUSTOMER' when IDENTITY_INSERT is set to OFF.

So at database level, I set

SET IDENTITY_INSERT CUSTOMER ON


When JPA persist again, I still got the same exception. What do I miss?
Don't MAKE me come back there with this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1354 times.
Similar Threads
Problem with OJB
HSQL db for JPA: auto incremented for a regular column
Problem persisting id field with an autoincrement field
Persistence error at new entry from Netbeans CRUD application
HSQL: strategy=GenerationType.IDENTITY. for auto-increment?
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 20:05:35.