mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
Test and fix for BUG 420.
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
package com.avaje.tests.basic;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.tests.model.basic.Article;
|
||||
import com.avaje.tests.model.basic.Section;
|
||||
|
||||
public class TestDeleteCascadingOneToMany extends TestCase {
|
||||
|
||||
public void testDeleteCascadingOneToMany() {
|
||||
Section s0 = new Section("some content");
|
||||
Article a0 = new Article("art1","auth1");
|
||||
a0.addSection(s0);
|
||||
|
||||
Ebean.save(a0);
|
||||
|
||||
Ebean.delete(a0);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,8 +1,13 @@
|
||||
package com.avaje.tests.model.basic;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.persistence.CascadeType;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Lob;
|
||||
import javax.persistence.ManyToOne;
|
||||
import javax.persistence.OneToMany;
|
||||
|
||||
import com.avaje.ebean.annotation.CacheStrategy;
|
||||
|
||||
@@ -24,6 +29,9 @@ public class Section extends BasicDomain {
|
||||
|
||||
@Lob
|
||||
String content;
|
||||
|
||||
@OneToMany(cascade=CascadeType.ALL)
|
||||
List<SubSection> subSections;
|
||||
|
||||
public Section() {
|
||||
}
|
||||
@@ -55,5 +63,20 @@ public class Section extends BasicDomain {
|
||||
public void setArticle(Article article) {
|
||||
this.article = article;
|
||||
}
|
||||
|
||||
public List<SubSection> getSubSections() {
|
||||
return subSections;
|
||||
}
|
||||
|
||||
public void setSubSections(List<SubSection> subSections) {
|
||||
this.subSections = subSections;
|
||||
}
|
||||
|
||||
public void addSubSection(SubSection s){
|
||||
if (subSections == null){
|
||||
subSections = new ArrayList<SubSection>();
|
||||
}
|
||||
subSections.add(s);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
package com.avaje.tests.model.basic;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.ManyToOne;
|
||||
|
||||
import com.avaje.ebean.annotation.CacheStrategy;
|
||||
|
||||
@CacheStrategy(useBeanCache=true)
|
||||
@Entity
|
||||
public class SubSection extends BasicDomain {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@ManyToOne
|
||||
private Section section;
|
||||
|
||||
private String title;
|
||||
|
||||
public SubSection() {
|
||||
}
|
||||
|
||||
public SubSection(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user