mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
#435 - Duplicate foreign key name with ManyToMany relations
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
package com.avaje.tests.m2m;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.tests.model.m2m.MnyTopic;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Added to test DDL generation for ManyToMany related back to itself.
|
||||
*/
|
||||
public class TestM2MSelfRelationship extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
Ebean.getDefaultServer();
|
||||
|
||||
// Create 2 roles r0 and r1
|
||||
MnyTopic r0 = new MnyTopic("r0");
|
||||
MnyTopic r1 = new MnyTopic("r1");
|
||||
|
||||
// Save r1 and r2
|
||||
Ebean.save(r0);
|
||||
Ebean.save(r1);
|
||||
|
||||
r0.getSubTopics().add(r1);
|
||||
Ebean.save(r0);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
package com.avaje.tests.model.m2m;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.JoinTable;
|
||||
import javax.persistence.ManyToMany;
|
||||
import javax.persistence.Version;
|
||||
import java.util.List;
|
||||
|
||||
@Entity
|
||||
public class MnyTopic {
|
||||
|
||||
@Id
|
||||
Long id;
|
||||
|
||||
String name;
|
||||
|
||||
@Version
|
||||
Long version;
|
||||
|
||||
@ManyToMany
|
||||
@JoinTable(name = "subtopics",
|
||||
joinColumns = @JoinColumn(name = "topic", referencedColumnName = "id"),
|
||||
inverseJoinColumns = @JoinColumn(name = "subtopic", referencedColumnName = "id"))
|
||||
List<MnyTopic> subTopics;
|
||||
|
||||
public MnyTopic() {
|
||||
|
||||
}
|
||||
|
||||
public MnyTopic(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Long getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
public void setVersion(Long version) {
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
public List<MnyTopic> getSubTopics() {
|
||||
return subTopics;
|
||||
}
|
||||
|
||||
public void setSubTopics(List<MnyTopic> subTopics) {
|
||||
this.subTopics = subTopics;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user