Hello we are using 4 database, oracle,mssql-2019, mssql-2022, mysql
Hibernate:6.4.4
@Id
@GenericGenerator(
name = "sequenceGenerator",
type = SequenceStyleGenerator.class ,
parameters = {
@org.hibernate.annotations.Parameter(
name = "optimizer",
value = "pooled-lo"
),
@org.hibernate.annotations.Parameter(
name = "initial_value",
value = "1"
),
@org.hibernate.annotations.Parameter(
name = "increment_size",
value = "5"
)
}
)
@GeneratedValue(
strategy = GenerationType.AUTO,
generator = "sequenceGenerator"
)
private Long id;
When I insert record to DB it works with mysql and oracle.However it throw exception for mssql-2019 +mssql-2022
org.springframework.dao.InvalidDataAccessResourceUsageException: could not execute statement [Cannot insert explicit value for identity column in table 'X' when IDENTITY_INSERT is set to OFF.] [insert into ledger (.//) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)]; SQL [....]) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)]
Yes, i don’t set any IDs manually.
The funny part it doesnt throw exception when inserted X record, it throwException when fetch it.(I verified the records in db)
.
When i change GenerationType as IDENTIFY
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
It is starting works properly.
But i don’t want to change GenerationType because as I said we are using 4 db
Besides all this why this weird issue happening , any idea ?