• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Hibernate One to One Example

 
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 .
 
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

reply
    Bookmark Topic Watch Topic
  • New Topic