spring - JPA foreign key NOT AS OBJECT -
i have 2 simple tables in mysql
user ---(one-to-many)--- expense
i using spring jpa generate theses 2 entities. expense has 'user_id' foreign key field references 'id' field in user table.
i use json in requests populate tables
user {"id":1, "username":"user"} expense { "id":1, "user_id":1, <--- value not null in mysql "expense":"expense" }
when calling api have user_id value , don't want pass whole object.
is there way tell spring integer foreign key references 'id' column in 'user' table?
all examples found online showed how achieve passing whole 'user' object in json.
my current implementation:
@entity public class user{ @id @generatedvalue(strategy = generationtype.identity) @column(name = "id", updatable = false, nullable = false) private int id; private string username; } @entity public class car{ @id @generatedvalue(strategy = generationtype.identity) @column(name = "id", updatable = false, nullable = false) private int id; @manytoone private user user_id; private string expense; }
Comments
Post a Comment