Hari
Hari

Reputation: 1

@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
@JoinColumn(name="id")
private xyz xyzDO;
}

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

Upvotes: 0

Views: 265

Answers (3)

James
James

Reputation: 18379

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

Upvotes: 0

masam
masam

Reputation: 2278

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).

Upvotes: 2

Stepan Vihor
Stepan Vihor

Reputation: 1070

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.

Upvotes: 0

Related Questions