One-to-One mapping with foreign key in target table and foreign key being the primary key
fails with Oracle
-----------------------------------------------------------------------------------------------------------
Key: HHH-6707
URL:
http://opensource.atlassian.com/projects/hibernate/browse/HHH-6707
Project: Hibernate Core
Issue Type: Bug
Components: core
Affects Versions: 3.6.6
Environment: Oracle 11g, Oracle JDBC 11.2.0.1.0
Reporter: Florian Rampp
Attachments: bugreports-hibernate-oracleUniquePk-1.0-SNAPSHOT-src.zip
When mapping a one-to-one parent/child relationship with the foreign key being in the
child table and forming its primary key, in addition to the primary key definition, a
unique constraint is generated (due to the one-to-one inverse mapping). A unique
constraint and a primary key definition on the same column is not accepted by Oracle. The
error is "ORA-02261: such unique or primary key already exists in the table"
when creating the schema.
The key entities:
{code:java}
@Entity
public class Parent {
@Id
Long id;
@OneToOne(cascade = CascadeType.ALL, orphanRemoval = true, mappedBy =
"parent")
Child child;
}
@Entity
public class Child implements Serializable {
@Id
@OneToOne(optional = false)
private Parent parent;
}
{code}
The resulting DDL is:
{code:sql}
create table Child (
parent_id number(19,0) not null,
primary key (parent_id),
unique (parent_id)
)
{code}
This issue is similar to
https://hibernate.onjira.com/browse/HBX-978. But I refiled it
here since I consider it to be a bug in Hibernate core. Also, I provided a test case that
can be used for regression tests. It needs to be executed with the arguments
{{-Dhibernate.connection.username=<USERNAME>
-Dhibernate.connection.password=<PASSWORD>
-Dhibernate.connection.url=<JDBC_URL>}}.
--
This message is automatically generated by JIRA.
For more information on JIRA, see:
http://www.atlassian.com/software/jira