本文介绍了@OneToMany在spring数据jpa中给出了空值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
public class Enterprise{
.....
@OneToMany(mappedBy = "enterprise", fetch = FetchType.EAGER)
private List<Organization> organizations;
.....
}
public class Organization{
....
@ManyToOne
@JoinTable(name = "enterprise_organization_map", joinColumns = {
@JoinColumn(name = "organization_id") }, inverseJoinColumns = { @JoinColumn(name = "enterprise_id") })
private Enterprise enterprise;
....
}
当我尝试获取Enterprise时,没有得到映射的组织.其返回的null.
When I tried to fetch Enterprise, I am not getting the mapped organizations. its returning null.
//打印声明
具有组织的企业:企业[企业ID = 13,企业名称= xyz,组织=空]
Enterprise with Organizations:Enterprise [enterpriseId=13, enterpriseName=xyz, organizations=null]
任何人都可以在这里帮助我.
Can anyone please help me here.
推荐答案
问题在于toString().
the problem is with the toString().
这篇关于@OneToMany在spring数据jpa中给出了空值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!