如何使用YML加载ManyToOne实体

时间:2012-05-15 11:48:04

标签: hibernate playframework yaml

我有以下yml和实体。
每次我通过Fixtures.loadModels()加载yml时,每个实体都会被持久化,但VSCode上的vsCat_id外键始终为null,并且关系不会持久存在。

我在这里错过了什么?

yml: 

VSCode(VS960):
   vsCode: VS960
   description: blabla

VSCategory(dvs1):
   name: Category 1
   vsCodes:
      - VSA960
      - VSA961


public class VSCode extends GenericModel {
    @Id
    public String            vsCode;
    public String            description;

    @ManyToOne
    public VSCategory vsCat;

    public VSCode(String code, String description) {
        this.vsCode = code;
        this.description = description;
    }
}

@Entity
public class VSCategory extends Model {

    public String name;

    @OneToMany(mappedBy="vsCat")
    public Set<VSCode> vsCodes;

    public VSCategory(String name){
        this.name = name;
        this.vsCodes = new HashSet();
    }
}

0 个答案:

没有答案