Core: 3.2.5 GA
Annotations: 3.3.0 GA
Dialect: org.hibernate.dialect.Oracle10gDialect
I have associated two classes via an optional one-to-many association with a join table. I established this pattern based on the "Java Persistence with Hibernate" Manning book. I am now attempting to explicitly name the Foreign Key constraints but it is not working as I expect.
I am defining the ForeignKey name on the MANY side, but when I generate the DDL it is assigning the name of the Foreign key to the inverse constraint as follows:
Quote:
[hibernatetool] create table qm.CHILD_TABLE (CHILD_ID number(19,0) not null, primary key (CHILD_ID));
[hibernatetool] create table qm.PARENT_TABLE (PARENT_ID number(19,0) not null, primary key (PARENT_ID));
[hibernatetool] create table qm.THE_JOIN_TABLE (CHILD_ID number(19,0) not null, PARENT_ID number(19,0), primary key (CHILD_ID));
[hibernatetool] alter table qm.THE_JOIN_TABLE add constraint FK47EF5907C513AE02 foreign key (CHILD_ID) references qm.CHILD_TABLE;
[hibernatetool] alter table qm.THE_JOIN_TABLE add constraint FK_CHILD_ID foreign key (PARENT_ID) references qm.PARENT_TABLE;
You can see that FK_CHILD_ID is assigned to the PARENT_ID column and the inverseName from the ForeignKey annotation is ignored.
What am I doing wrong?
Thanks,
Mark
Here are the class definitions with annotations:
Code:
@Entity
@Table(name = "PARENT_TABLE")
public class Parent implements Serializable
{
@Id
@GeneratedValue(generator = "hibinc")
@GenericGenerator(name = "hibinc", strategy = "increment")
@Column(name = "PARENT_ID")
private Long id = null;
@OneToMany(mappedBy = "parent")
private Set<Child> children = new HashSet<Child>();
}
@Entity
@Table(name = "CHILD_TABLE")
public class Child implements Serializable
{
@Id
@GeneratedValue(generator = "hibinc")
@GenericGenerator(name = "hibinc", strategy = "increment")
@Column(name = "CHILD_ID")
private Long id = null;
@ManyToOne
@JoinTable(
name="THE_JOIN_TABLE",
joinColumns = {@JoinColumn(name="CHILD_ID")},
inverseJoinColumns = {@JoinColumn(name="PARENT_ID")})
@org.hibernate.annotations.ForeignKey(name="FK_CHILD_ID", inverseName="FK_PARENT_ID")
private Parent parent;
}