java - Error: The given id must not be null for GeneratedValue in JPA -


my object:

@entity @table(name="user") public class user {     @id     @column(name="uid")     @generatedvalue(strategy=generationtype.identity)     private long id;    //more code  } 

when post user json without uid, getting error the given id must not null. should not case while uid should generated database. please point missing.

json:

{ "email": "john@mail.com", "name": "john doe", "phone": "98-765-4445" } 

error:

{ "timestamp": 1501058952038, "status": 500, "error": "internal server error", "exception": "org.springframework.dao.invaliddataaccessapiusageexception", "message": "the given id must not null!; nested exception java.lang.illegalargumentexception: given id must not null!", "path": "/api/user/" } 

it bad, calling foo(user.getid()) before persisting user object. anyways, take aways this; @generatedvalue(strategy=generationtype.identity) correct code , generates identical ids while persisting. , long not problem. thanks.


Comments

Popular posts from this blog

python - Selenium remoteWebDriver (& SauceLabs) Firefox moseMoveTo action exception -

html - How to custom Bootstrap grid height? -

transpose - Maple isnt executing function but prints function term -