java - one-to-one mapping hibernate using foreign key association -
am new hibernate learning entity mapping using hibernate framework via instead of annotation using xml mapping entities
here have 2 classes employee , address [address target class , employee source class i.e employee table have foreign key column refers address table primary key]
class employee{ string name; int id; address addr; //getter , setter methods } class address{ string state; string city }
mapping.hbm.xml file:-
<hibernate-mapping> <class name="employee" table="emp"> <id name="id" column="id"> <generator class="assigned"/> </id> <property name="name" column="emp_name"/> <one-to-one name="addr" class="address" foreign-key="addr_id" cascade="all"/> </class> <!--mapping address entity--> <class name="address" table="address> <property name="city"/> <property name"state"/> </class> </hibernate-mapping>
note:- using mysql in table level did not add foreign key constraint employee table
and question while try save employee entity addr_id value not stored in employee table how resolve issue.in web of things using annotations or shared primary key.how solve issue kindly me
change mapping. need qualify class name , indicate join column, pk of employee, column id
.
employee
<class name="employee" table="emp"> <id name="id" column="id"> <generator class="assigned"/>
address entity have refer pk of employee, id
in case :
<one-to-one name="addr" class="my.package.employee" unique="true" not-null="true" cascade="all"/>
Comments
Post a Comment