-->
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.  [ 1 post ] 
Author Message
 Post subject: JPA @PrimaryKeyJoinColumn with Hibernate?
PostPosted: Sun Nov 04, 2012 4:35 pm 
Newbie

Joined: Fri Mar 11, 2005 11:18 am
Posts: 8
I try to use @OneToOne relationship by sharing the same primary keys values. I found this example :

Code:
@Entity
public class Body {
    @Id
    public Long getId() { return id; }

    @OneToOne(cascade = CascadeType.ALL)
    @PrimaryKeyJoinColumn
    public Heart getHeart() {
        return heart;
    }
    ...
}

@Entity
public class Heart {
    @Id
    public Long getId() { ...}
}

at http://docs.jboss.org/hibernate/annotations/3.5/reference/en/html_single/

When i run the code i see only two table being create and there is not added any foreign key constraints like it is added when i use JoinColumn

So the generated DB code for create table is :

Code:
create table Body (
        id bigint generated by default as identity (start with 1),
        primary key (id)
    )
create table Heart (
        id bigint generated by default as identity (start with 1),
        primary key (id)
    )

After NO constrains added...

When running this agains EclipseLink implementation :

Code:
CREATE TABLE BODY (ID BIGINT NOT NULL, PRIMARY KEY (ID))
CREATE TABLE HEART (ID BIGINT NOT NULL, PRIMARY KEY (ID))
**ALTER TABLE BODY ADD CONSTRAINT FK_BODY_ID FOREIGN KEY (ID) REFERENCES HEART (ID)**
CREATE TABLE SEQUENCE (SEQ_NAME VARCHAR(50) NOT NULL, SEQ_COUNT NUMERIC(38), PRIMARY KEY (SEQ_NAME))
INSERT INTO SEQUENCE(SEQ_NAME, SEQ_COUNT) values ('SEQ_GEN', 0)

exactly what i expected to get from Hibernate.

Any idea if Hibernate is supposed to behave like this ?


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

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.