Reputation: 367
Address has many-to-one relationship with person like :
Person :
@Id
@Column(name="personid")
private Long personId;
private String firstName;
private String lastName;
private String email;
@OneToMany(cascade = CascadeType.ALL,mappedBy="person",targetEntity=Address.class,fetch=FetchType.LAZY)
private List addressArray=new ArrayList<>();
public Person() {
}
and Address :
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name="personId")
private Person person;
I want to access person's firstname from the address object like "address.person.firstname" but it always eager load the person ?
Upvotes: 1
Views: 2304
Reputation: 18379
What do you mean by inverse entity?
In general, yes, LAZY is supported on any relationship type. For ManyToOne you must ensure you use the EclipseLink agent to allow dynamic weaving (or JavaEE/Spring), you can also use static weaving.
http://wiki.eclipse.org/EclipseLink/UserGuide/JPA/Advanced_JPA_Development/Performance/Weaving
Upvotes: 2