| 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?
 
 
 |