Ole Ole - 1 year ago 63
Java Question

When using @OnetoOne(optional=false) does the target reference always get loaded?

In this example from this understanding-jpa-part-2-relationships-the-jpa-way tutorial will an

entity always be loaded when an
entity is loaded? Putting a code snippet from the
class below for reference:

@JoinColumn(name = "ORDER_ID")
private Order order;

Answer Source

Yes. Because if you don't specify the attribute fetch the default FetchType is EAGER.

If you want it loaded LAZY

@OneToOne(optional=false, fetch=FetchType.LAZY)
@JoinColumn(name = "ORDER_ID") 
private Order order;   
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download