Bug 397 : Not a Bug - @ManyToMany fails with duplicate column name
Priority 
High
Reported Version 
 
Logged By 
mjakl
Status 
Fixed
Fixed Version 
2.7.7
Assigned To 
 
Product 
Ebean - core
Duplicate Of 
 
Created 
02/05/2012
Updated 
02/05/2012
Type 
Bug
 
Attachments 
No attachments

When modelling a many-to-many relation to the same class, ebean uses the same fk name twice.

class Person {
@Id
public Long id;
@ManyToMany
public List friends; // <-----
}

 
mjakl 02 May 08:43
Version 2.7.3

The bug-report form lost the version info.
I'm experiencing the problem with ebean 2.7.3.

mjakl 02 May 08:55
Solution

The solution, of course, is to manually specify the join table properties:
class Person {
@Id
public Long id;
@ManyToMany
@JoinTable(
name = "friends",
joinColumns = @JoinColumn(name = "friend_id", referencedColumnName = "id"),
inverseJoinColumns = @JoinColumn(name = "person_id", referencedColumnName = "id")
)
public List friends;
}

Rob 27 May 02:40
Won't change behavior

I don't think we should change Ebean's behavior. In this case I believe you should explicitly specify the foreign key columns.

Leaving Ebean unchanged unless someone argues for some other approach.

woResponse

Upload a file