Java Spring Boot Hibernate need Primary Key and How to Add it in SQL Server — Hibernate org.hibernate.AssertionFailure

tanut aran
Apr 2, 2024

--

I assume you have this error on Spring Boot screen

org.hibernate.AssertionFailure: HHH000099:
an assertion failure occurred
(this may indicate a bug in Hibernate,
but is more likely due to unsafe use of the session):
org.hibernate.AssertionFailure: null identifier

And you check and see that nothing on your table has NOT NULL

Real problem: Your Hibernate need the primary key

So you add it into the model

@Data
@Entity
public class StoreDetail {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
private String branchCode;
private String areaCode;
...

Then add it into your SQL Server table

ALTER TABLE dbo.YourTable
ADD ID INT IDENTITY

Or with constraint

ALTER TABLE dbo.YourTable
ADD CONSTRAINT PK_YourTable
PRIMARY KEY(ID)

--

--

tanut aran
tanut aran

Written by tanut aran

Co-founder and Coder at work !

No responses yet