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 ?