-->
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.  [ 2 posts ] 
Author Message
 Post subject: @ForeignKey doesn't work for one-to-one shared PK
PostPosted: Mon Jul 23, 2007 9:13 pm 
Newbie

Joined: Mon Jul 23, 2007 7:52 pm
Posts: 1
Hi,

Hibernate Annotations 3.3.0.GA
Hibernate Tools 3.2.0.Beta9
Hibernate Core 3.2.3.GA
Hibernate EntityManager 3.3.1.GA
HSQLDB 1.8.0

I have a bidirectional "one-to-one shared primary key" association.

My entities are:
Code:
@Entity
@Table(name="USERS")
public class User implements Serializable {

    @Id
    @GeneratedValue
    @Column(name="USER_ID")
    private Long id;
   
    @Column(name="USER_NAME", length=64, nullable=false)
    private String name;

    @OneToOne(fetch=FetchType.LAZY, mappedBy="user")
    private Address shippingAddress;

    ... ...

}


Code:
@Entity
public class Address implements Serializable {

    @Id
    @GeneratedValue(generator="myForeignGenerator")
    @org.hibernate.annotations.GenericGenerator(
        name="myForeignGenerator",
        strategy="foreign",
        parameters=@Parameter(name="property", value="user")
    )
    @Column(name="ADDRESS_ID")
    private Long id;
   
    @Column(name="CITY", length=64, nullable=false)
    private String city;
   
    @OneToOne(fetch=FetchType.LAZY, optional=false)
    @PrimaryKeyJoinColumn
    @org.hibernate.annotations.ForeignKey(name="FK_ADDRESS_ADDRESS_ID")
    private User user;

    ... ...

}


The SQL DDL generated by hbm2ddl:
Code:
create table USERS (
    USER_ID bigint generated by default as identity (start with 1),
    USER_NAME varchar(64) not null,
    primary key (USER_ID)
);

create table ADDRESS (
    ADDRESS_ID bigint not null,
    CITY varchar(64) not null,
    primary key (ADDRESS_ID)
);

alter table ADDRESS
      add constraint FKE66327D4302E1347
      foreign key (ADDRESS_ID)
      references USERS;

The name of the foreign key is not "FK_ADDRESS_ADDRESS_ID" but FKE66327D4302E1347.
How can I create a correct(=FK_ADDRESS_ADDRESS_ID) foreign key name?

Thanks in advance.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 25, 2007 1:26 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Sounds like a bug to me, can you open a JIRA issue with a minimal runnable test case? A patch fixing the issue would be even better though ;)

_________________
Emmanuel


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.