File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Object Relational Mapping and the fly likes Hibernate One to One Example Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Hibernate One to One Example " Watch "Hibernate One to One Example " New topic

Hibernate One to One Example

Ravi Kiran Va
Ranch Hand

Joined: Apr 18, 2009
Posts: 2234


I am working on a simple Hibernate One to One Mapping Application .

For this i created two Tables Car and Registration as shown :

Car and Registration number are basically related to each other as one to one, that means for a single car, there could be at most a single registration number, and vice versa.

create table Car(car_name varchar2(20),car_model varchar2(50),primary key(car_name))

create table Registration(registration_number varchar(20),car_name varchar(20) not null, primary key(registration_number),unique(car_name))

Made car_name as Unique , so to have one to One mapping .

By IDE Reverseengineering i got these hbm files

This is for Car

This is for Registration :

Please tell me is this mapping correct because i have a seen a example in a site of One to One Hibernate where the author uses

<many-to-one> inside the hbm file .

Please let me know .

Save India From Corruption - Anna Hazare.
xsunil kumar
Ranch Hand

Joined: Dec 14, 2009
Posts: 137
Your both hbm files are telling about individual entity. They are not telling about one to one relationship.You need to provide this in any one of your entity depends upon which entity you want to make it as souce. means which entity has foreign column.

I agree. Here's the link:
subject: Hibernate One to One Example
It's not a secret anymore!