JPA 2.0 Hibernate 4.3.5
Hi,
Below is my OneToOne mapping (with an example code whereby 1 customer can only have 1 order)
class Customer {
private Order order;
@OneToOne(mappedBy="customer", fetch=FetchType.LAZY)
public Order getOrder() { return order; }
public void setOrder(Order order) { this.order = order ; }
}
class Order {
private Customer customer;
@OneToOne(fetch=FetchType.LAZY)
@JoinColumn(name="cust_id")
public Customer getCustomer() { return customer; }
public void setCustomer(Customer customer) { this.customer = customer; }
}
Order order = em.find(Order.class, 4);
System.out.println(order.getCustomer());
</code>
Above, the calling code actually leads to 3 ie select statements
Line 1 calling
select * from order where id = ?
Line 2 calls the following two statements
select * from customer where id = ?
select * from order where cust_id = ?
My question is: Shouldn't there be only two queries (for example, No. 1 and No. 2), given that the LAZY option is turned on at both ends?
Thank you Rahkesh
source
share