my dog learned polymorphism*
The moose likes Object Relational Mapping and the fly likes one-to-one mapping. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "one-to-one mapping." Watch "one-to-one mapping." New topic
Author

one-to-one mapping.

harshad kadam
Greenhorn

Joined: Mar 19, 2011
Posts: 8
hello,
i am beginner to hibernate. please guide me with one to one mapping.

DB table structure:





Employee.java



EmployeeContact.java


Employee.hbm.xml


EmployeeContact.hbm.xml


Here in EmployeeBean.java, i construct employee object



Here in EmployeeDaoImpl.java i save the employee object





The problem is one to one mapping. The EmployeeContact object gets saved except employee_id. EMPLOYEE_ID remains null in EMPLOYEE_CONTACT table. Please guide me where the configuration is fallen short.
ntumba lobo
Ranch Hand

Joined: Oct 21, 2008
Posts: 180
why are you using "property-ref" in your Employee mapping ?
It is not necessary to establish the one-to-one relationship unless you work with legacy database.
It could be the problem.


SCJP 5 , SCWCD 5, SCEA 5
harshad kadam
Greenhorn

Joined: Mar 19, 2011
Posts: 8
ntumba lobo wrote:why are you using "property-ref" in your Employee mapping ?
It is not necessary to establish the one-to-one relationship unless you work with legacy database.
It could be the problem.



I reffered "property-ref" from this tutorial.

As per your advice i removed "property-ref" but didn't work for me. Problem persists.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: one-to-one mapping.