• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hibernate One to One Example

 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

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 .
 
xsunil kumar
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic