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.