java - Setting value of different JSON key to field Play framework -
i creating rest service in play framework , have route reads json request. json in format:
{ "email":"test@test.com", "password":"pw", "address":{ "city":"cityname", "country":"countryname"} }
then use user = json.fromjson(json, user.class);
parse json user class. in database, have tables 1 one relation like:
user:
email varchar, name string
address:
email varchar, city varchar, address varchar
where email foreign key.
since json receive has 5 values, when play framework saves new record database,in address saves city , address, , email field saved null. , later on can not retrieve value of address item of related user record since foreign key connects them saved null. (these sql queries: )
is there annotation or other way how can use email value json email value in address table?
here how wrote model classes:
@entity @table(name = "user") public class user extends model{ @id @column(length = 80) private string email; @column(length = 100) private string password; @onetoone(cascade = cascadetype.all, mappedby = "user") private address address; } @entity @table(name = address public class address extends model{ @onetoone() @joincolumn(name = "email") private user user; @column(length = 100) private string city; @column(length = 100) private string country; }
why don't try saving address first, later when object address managed orm set object address object user , persist object user.
something this:
- parse json user object
- get address user object parsed.
- persist address object
- set address object user object again
- persist user object.
i hope help.
Comments
Post a Comment