我在播放框架中使用了ebean,我在映射2个连接表之间的多对多关系时遇到了问题。假设我们有3个实体,人,公司和专业。一个人可以有很多职业。一个人可以为许多公司工作。公司可以雇佣许多职业的人员。
这是我的代码:
@Entity
public class Company extends Model {
@Id
public Long id;
@OneToMany(fetch = FetchType.LAZY, mappedBy = "company")
public List<CompanyPerson> companyPersons;
@OneToMany(fetch = FetchType.LAZY, mappedBy = "company")
public List<CompanyProfession> companyProfessions;
...
}
@Entity
public class Profession extends Model {
@Id
public Long id;
@OneToMany(fetch = FetchType.LAZY, mappedBy = "profession")
public List<CompanyProfession> companyProfessions;
...
}
@Entity
public class Person extends Model {
@Id
public Long id;
@OneToMany(fetch = FetchType.LAZY, mappedBy = "person")
public List<CompanyPerson> companyPersons;
...
}
@Entity
public class CompanyPerson extends Model {
@EmbeddedId
public CompanyPersonId id = new CompanyPersonId();
@ManyToOne
@JoinColumn(name = "company_id")
private Company company;
@ManyToOne
@JoinColumn(name = "person_id")
private Person person;
@ManyToMany(mappedBy = "companyPersons")
public List<CompanyProfession> companyProfessions;
...
}
@Entity
public class CompanyProfession extends Model {
@EmbeddedId
public CompanyProfessionId id = new CompanyProfessionId();
@ManyToOne
@JoinColumn(name = "company_id")
private Company company;
@ManyToOne
@JoinColumn(name = "profession_id")
private Person person;
@ManyToMany(cascade = CascadeType.ALL)
public List<CompanyPerson> companyPersons;
...
}
我收到以下错误:
注入构造函数时出错,javax.persistence.PersistenceException:在[models.CompanyProfession.companyPersons]上加入时出错。找不到[null]的本地匹配可能是@JoinColumn中的错误 at play.db.ebean.EbeanDynamicEvolutions。(EbeanDynamicEvolutions.java:36)
我尝试添加JoinColumn(name =&#34; companyperson_id&#34;)但这只是将错误从[null]更改为[companyperson_id]。 不知道该怎么做。有什么帮助吗?