提前感谢您阅读本文。我现在正试图解决我的问题一个多星期,但找不到解决方案。
我正在尝试通过YAML文件填充我的ManyToMany关系,但由于某种原因它不起作用。
她是我的班级:
@Entity
public class Company extends Model {
@Id
public Integer id;
@ManyToMany(fetch = FetchType.EAGER, cascade = CascadeType.PERSIST)
@JsonManagedReference
public Set<Language> languages = new TreeSet<Language>();
@Entity
public class Language extends Model {
@Id
public Integer id;
public String name;
@ManyToMany(mappedBy = "languages", cascade = CascadeType.PERSIST)
@JsonBackReference
public Set<Company> companies = new TreeSet<Company>();
YAML:
- &language1 !!models.Language
id: 1
name: English
- &language2 !!models.Language
id: 2
name: Mandarin
- &language3 !!models.Language
id: 3
name: Cantonese
- &company1 !!models.Company
id: 1
languages:
? *language1
? *language2
? *language3
- &company2 !!models.Company
id: 2
languages:
? *language1
? *language3
- &company3 !!models.Company
id: 3
languages:
? *language1
? *language3
全局:
public class Global extends GlobalSettings {
@Override
public void onStart(Application app) {
// Check if the database is empty
if (User.find.findRowCount() == 0) {
Ebean.save((List) Yaml.load("initial-data1.yml"));
}
}
}
当我尝试在Json中获取公司对象时,语言Set为空。
感谢您的帮助!