*
The moose likes Object Relational Mapping and the fly likes Problem in <one-to-one> relation 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 "Problem in <one-to-one> relation mapping" Watch "Problem in <one-to-one> relation mapping" New topic
Author

Problem in <one-to-one> relation mapping

Sai Kiran nukala
Greenhorn

Joined: Aug 16, 2009
Posts: 9
Hi frnds...i got a prob. i am posting everything what i wrote....In database there are two tables Person and Car

Person table(id,name,address)
Car table(id,brand,person_id)....person_id is FK from person table.


Person Class:



Car Class:


Car Mapping file:



Person Mapping file:


Connection class where i created session and all others.




here i created one-to-one mapping using <many-to-one> relation by putting "unique" attribute to true in Person mapping file. And when i execute it i got an error which is shown below:


Frnds please help me in clearing this mapping relation i'm very confused with this. Waiting for your valuable replies. If i did any mistake in the above code. Please correct me...

Thank in advance.
Ben Narendren
Greenhorn

Joined: Oct 01, 2009
Posts: 19
Since the CAR table has the PERSON_ID column (I find this a little unusual though), I am assuming the Car object is pointing to a Person object. In that case your Car class should be



and your car mapping should be




If you truly really want a bidirectional relationship and wish a pointer from person to car, the person mapping should be



 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem in <one-to-one> relation mapping
 
Similar Threads
Cannot add or update a child row: a foreign key constraint fails
Problem in mapping
Creating one-to-one mapping: ConstraintViolationException
Hibernate @GeneratedValue problem
java.sql.SQLException: Cannot add or update a child row: a foreign key constraint fails