-->
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: Naming Foreign Keys with a Join Table
PostPosted: Tue Oct 30, 2007 11:06 am 
Newbie

Joined: Tue Oct 30, 2007 10:32 am
Posts: 1
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;
}



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.