-->
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: Duplicate foreign keys
PostPosted: Mon Sep 04, 2006 8:06 am 
Newbie

Joined: Mon Jun 19, 2006 3:18 am
Posts: 2
Hi,
I'm facing a problem where 2 identical foreign keys (for the same column and table) are created by hbm2ddl task as a result of a few many-to-many relations.
I narrowed this down to 2 classes: Member and Group.
Group extends Member. Member contains a set of parent groups and Group contains a set of child groups.
Here's the code:
// Member
@Entity
@Table(name="PARENT_TABLE")
@Inheritance(strategy= InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name="type",discriminatorType=DiscriminatorType.STRING)
public abstract class Member {

private String name;
private Set<Group> parentGroups;

@Id
@Column(name="NAME", length=100, nullable=false)
public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

@ManyToMany(
targetEntity= Group.class
)
@JoinTable(
name="MEMBER_TO_GROUP",
joinColumns={@JoinColumn(name="MEMBER_ID")},
inverseJoinColumns={@JoinColumn(name="GROUP_ID")}
)
public Set<Group> getParentGroups() {
return parentGroups;
}

public void setParentGroups(Set<Group> parentGroups) {
this.parentGroups = parentGroups;
}
}

// Group
@Entity
@DiscriminatorValue("group")
public class Group extends Member {

private Set<Group> childGroups;

@ManyToMany(
mappedBy="parentGroups",
targetEntity=Group.class
)
public Set<Group> getChildGroups() {
return childGroups;
}

public void setChildGroups(Set<Group> childGroups) {
this.childGroups = childGroups;
}
}

The result of this is 2 identical foreign keys:
alter table MEMBER_TO_GROUP
add constraint FK16A5E3A017C979DF
foreign key (MEMBER_ID)
references PARENT_TABLE;

alter table MEMBER_TO_GROUP
add constraint FK16A5E3A08AD6A8FA
foreign key (MEMBER_ID)
references PARENT_TABLE;

It seems to me like a bug.
Did anyone else encounter this issue?
Is there a solution for it?


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.