Thursday, May 10, 2012

Too L@zy for Debug

If you use JPA in your application and have @Lazy fetching on your Entities properties, please note that debugging might be impossible.

for example:
public class Order[
@OneToMany(fetch=FetchType.LAZY,mappedBy = "order")
Set items;
I encounter the issue with Spring IDE (STS 2.9), Spring 3.1 and JUnit 4.
When running a JUnit test  against the Service layer which needed to read lazy properties - same line of code (the invocation of a Lazy property) failed on Debug (exception) however succeeded on Run mode.

The problematic line is something like that:
Order order = getOrderById(orderId);
order.getItems(); // Exception on debug

Black magic indeed.

Hope this save time to someone..