java - JPA OneToOne relationship -
i building project using play framework , having trouble getting head around jpa @onetoone relationships
.
i have 2 classes:
user object
@entity @table( name="users" ) public class users extends model { @onetoone( mappedby="userid", fetch=fetchtype.lazy, cascade = cascadetype.all ) @foreignkey( name="userid", inversename="userid" ) usersettings usersettings; public userid; public username; }
usersettings
@entity @table( name="user_settings" ) public class usersettings extends model { @onetoone( cascade = cascadetype.all,targetentity=user.class ) public string userid; public string xml; public usersettings( string userid ){ this.userid = userid; } }
the idea trying set userid
field within user
foreign key within usersettings
. have tried few different ways achieve , code throws error. common error recveive is: referenced property not (one|many)toone.
however, when try set userid
in usersettings
using code above, receive following exception:
a javax.persistence.persistenceexception has been caught, org.hibernate.propertyaccessexception: not field value reflection getter of reader.user.id
can explain how can achieve desired goal?
read section 5.2 of hibernate reference difference between entities , values. you're trying map string entity. entities can (one|many)toone, error telling you. i.e., instead of string userid
, should using user user
, , instead of mappedby="userid"
, mappedby="user"
.
Comments
Post a Comment