mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
#445 - Multiple @*ToMany relations referencing the same type
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
package com.avaje.tests.m2m;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.tests.model.m2m.MailBox;
|
||||
import com.avaje.tests.model.m2m.MailUser;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class TestM2MMultipleLists extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
MailUser u = new MailUser();
|
||||
u.setName("mailUser1");
|
||||
|
||||
MailBox m1 = new MailBox();
|
||||
m1.setName("mailBox1");
|
||||
|
||||
u.getInbox().add(m1);
|
||||
Ebean.save(u);
|
||||
|
||||
u = Ebean.find(MailUser.class, u.getId());
|
||||
|
||||
assertEquals(1, u.getInbox().size());
|
||||
assertEquals(0, u.getOutbox().size());
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package com.avaje.tests.model.m2m;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Version;
|
||||
|
||||
@Entity
|
||||
public class MailBox {
|
||||
|
||||
@Id
|
||||
Long id;
|
||||
|
||||
@Version
|
||||
Long version;
|
||||
|
||||
String name;
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Long getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
public void setVersion(Long version) {
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
package com.avaje.tests.model.m2m;
|
||||
|
||||
import javax.persistence.CascadeType;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.JoinTable;
|
||||
import javax.persistence.ManyToMany;
|
||||
import javax.persistence.Version;
|
||||
import java.util.List;
|
||||
|
||||
@Entity
|
||||
public class MailUser {
|
||||
|
||||
@Id
|
||||
Long id;
|
||||
|
||||
@Version
|
||||
Long version;
|
||||
|
||||
String name;
|
||||
|
||||
@ManyToMany(cascade = CascadeType.ALL)
|
||||
@JoinTable(name = "mail_user_inbox")
|
||||
List<MailBox> inbox;
|
||||
|
||||
@ManyToMany(cascade = CascadeType.ALL)
|
||||
@JoinTable(name = "mail_user_outbox")
|
||||
List<MailBox> outbox;
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Long getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
public void setVersion(Long version) {
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public List<MailBox> getInbox() {
|
||||
return inbox;
|
||||
}
|
||||
|
||||
public void setInbox(List<MailBox> inbox) {
|
||||
this.inbox = inbox;
|
||||
}
|
||||
|
||||
public List<MailBox> getOutbox() {
|
||||
return outbox;
|
||||
}
|
||||
|
||||
public void setOutbox(List<MailBox> outbox) {
|
||||
this.outbox = outbox;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user