-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: Specifying multiple one-to-one relationships between tables
PostPosted: Sat Aug 19, 2017 8:04 am 
Newbie

Joined: Sat Aug 19, 2017 7:57 am
Posts: 2
There are two tables: Airplane and Engine

Engine: [Engine_ID, Engine_Name, Engine_Position, Airplane_Owner_ID].
Airplane: [Airplane_ID, Airplane_Name,...]
Engine_Position = {Right, Left}

Each plane has two engine (Left_Engine and Right_Engine). And a unique constraint on Engine (Airplane_Owner_ID, Engine_Position).
Therefore there are two one-to-one relationships defined between the Airplane and Engine tables.

How can these relationships be specified in Hibernate and related class in JPA?


Top
 Profile  
 
 Post subject: Re: Specifying multiple one-to-one relationships between tables
PostPosted: Sat Aug 19, 2017 11:05 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
The best way to do it is to change the schema as follows:

Engine: [Engine_ID, Engine_Name].
Airplane: [Airplane_ID, Airplane_Name, Left_Engine_ID, Right_Engine_ID]

This is a much better approach since you said that an engine can only have 2 engines. Using your previous schema, an airplane could end-up with 100 left engines and 300 right ones.


Top
 Profile  
 
 Post subject: Re: Specifying multiple one-to-one relationships between tables
PostPosted: Sat Aug 19, 2017 3:36 pm 
Newbie

Joined: Sat Aug 19, 2017 7:57 am
Posts: 2
vlad wrote:
The best way to do it is to change the schema as follows:

Engine: [Engine_ID, Engine_Name].
Airplane: [Airplane_ID, Airplane_Name, Left_Engine_ID, Right_Engine_ID]

This is a much better approach since you said that an engine can only have 2 engines. Using your previous schema, an airplane could end-up with 100 left engines and 300 right ones.

Would you please tell me the jpa?


Top
 Profile  
 
 Post subject: Re: Specifying multiple one-to-one relationships between tables
PostPosted: Sun Aug 20, 2017 1:42 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
Sure. Here's the best way to map a @OneToOne relationship with JPA and Hibernate.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.