[hibernate-issues] [Hibernate-JIRA] Commented: (HBX-524) Reverse of one-to-one relationships
Erik Lund Jensen (JIRA)
noreply at atlassian.com
Fri Apr 11 08:15:33 EDT 2008
[ http://opensource.atlassian.com/projects/hibernate/browse/HBX-524?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_29988 ]
Erik Lund Jensen commented on HBX-524:
--------------------------------------
Hi,
The mapping of one-to-one is a bit tricky to solve.
Firstly, Oracle specifies a couple of "laws":
Primary Key (PK) - Foreign Key (FK) LAW #1: If the foreign key column is part of the primary key (or part of an index) then the relationship between the tables will be one to many (1:M).
Primary Key (PK) - Foreign Key (FK) LAW #2: If the foreign key column represents the entire primary key (or the entire index) then the relationship between the tables will be one to one (1:1).
See also http://www.sqlinfo.net/oracle/oracle_Create_foreign_key_contraints.php
Secondly, one-to-one may be mapped using the @PrimaryKeyJoinColumn, however, it is hard to decide the value of the attribute "optional", as Oracle schema does specify if the relation includes 1-zero. Further more, one-to-one relations may also be mapped without @PrimaryKeyJoinColumn.
I do not see, an general solution to this problem. One solution could be adding new methods to ReverseEngineeringStrategy to support one-to-one mapping and then let the application developer do the implementation details in the specific strategy.
/Erik Lund Jensen
Note:
Just an example of how one-to-one relation can be mapped:
@Entity
public class Master
{
@Id
private Long id;
and the weak entity:
@OneToOne
@PrimaryKeyJoinColumn
private Slave slave;
> Reverse of one-to-one relationships
> -----------------------------------
>
> Key: HBX-524
> URL: http://opensource.atlassian.com/projects/hibernate/browse/HBX-524
> Project: Hibernate Tools
> Issue Type: Bug
> Components: reverse-engineer
> Affects Versions: 3.1beta2
> Environment: HIbernate 3.1, Oracle 9i
> Reporter: Andrea Cattani
>
> Hi,
> I've posted this issue to the forum and got this response from Max, Hibernate Team:
> "the reveng tools does not detect this as a one-to-one. it probably could, so add a request/patch to jira."
> The problem I've faced is the following:
> I have two tables, let's say
> - table A with column ID (PK) and other fields
> - table B with column ID (PK) and other fields
> table B has a foreign key constraint against table A, from column ID to column ID (one-to-one)
> When I reverese the tables with the HibernateTools I have such a resultant mapping for table B:
> <class name="B" table="B" schema="SCHEMA">
> <id name="id" type="string">
> <column name="ID" length="12" />
> <generator class="assigned" />
> </id>
> <[b]many-to-one name[/b]="a" class="A" update="false" insert="false" fetch="select">
> <column name="ID" length="12" not-null="true" unique="true" />
> </many-to-one>
> ....
> And this one for table A:
> <class name="A" table="A" schema="SCHEMA">
> <id name="id" type="string">
> <column name="ID" length="12" />
> <generator class="assigned"/>
> </id>
> <set name="b" inverse="true">
> <key>
> <column name="ID" length="12" not-null="true" unique="true" />
> </key>
> <[b]one-to-many[/b] class="B" />
> </set>
> </class>
> while I was expecting something like:
> [i]<one-to-one name="a" class="A" constrained="true"/>[/i]
> in table B, and the same (or nothing) in table A
> Thank you
> Andi
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
More information about the hibernate-issues
mailing list