开发者

@ManyToOne relationship,JPA

I have a bidirectional many to one relationship. When I retrieve the parent object from the table, all the child objects should get retrieved but only the first one is getting retrieved The parent looks like

@Entity
public class xyz{
@OneToMany(mappedBy="xyz",cascade=CascadeType.PERSIST,fetch=FetchType.EAGER)
private Set<zyx> zyxDO;}

The child class looks like

public class zyx{
@ManyToOne
@J开发者_高级运维oinColumn(name="id")
private xyz xyzDO;
}

Is there any annotation where I can retrieve all the rows of the underlying database


Maybe it is a typo, but the value of mappedBy should be the name of the attribute in the owning entity that points back to the inverse entity, in this case xyzDO.

And maybe because you are using a Set instead of a Collection could cause that only one child is retrieved (if they are identical).


What do you mean by retrieve all the rows of the underlying database? You retrieve only the children which parent's key set. Note also, that fetch eager can easily cause great performance issues, because children will be fetched always, even if you don't need them.


Ensure you set both sides of the relationships when adding/setting the relationship.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜