1
如果我有这样的代码中的双向test_data.yml
@Entity
public class Category extends Model {
public String title;
public Category() {}
public Category(String title) {
this.title = title;
}
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
@JoinColumn(name="parent")
public List<Category> children = new LinkedList<Category>();
@ManyToOne
@JoinColumn(name="parent", insertable=false, updatable=false)
public Category parent;
public void addChild(Category child) {
Category root = this;
child.parent = root;
root.children.add(child);
root.save();
}
}
,我想在我的test_data.yml创建测试数据文件我怎么可以键入吗?我的意思是,这是双向..
例如,如果我会做这样的:
Category(root1):
title: root
children: [child1, child2]
Category(child1):
title: child1
parent: root1
Category(child2):
title: child2
parent: root1
我会得到这个错误:
Cannot load fixture initial-data.yml: No previous reference found for object of type children with key child1
但如果我不键入此:children: [child1, child2]
然后我会有错误的结构,child1和child2不会引用根。
我固定:类别(child1): 标题:child1 类别(的child2): 标题:的child2 类别(目录root1): 标题:根 小孩:[child1,的child2] – ses 2011-04-29 09:06:59