openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Beniamin Mazan ...@mazan.pl>
Subject EAGER vs. LAZY loading - weird behaviour in OpenJPA 1.0.1
Date Tue, 08 Jul 2008 11:56:36 GMT

Hi
I refactored my source code quoted in
http://n2.nabble.com/Incredible-set-of-statements-td221053.html
Currently I use:

@Entity 
public class Customer {
...
	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER, mappedBy =
"customer")
	private Set<Product> products = new HashSet<Product>();
...
}

@Entity
public class Product {
...
    @ManyToOne(cascade = { CascadeType.MERGE, CascadeType.REFRESH }, fetch =
FetchType.EAGER)
    @JoinColumn(name = "billacc_id", nullable = false)
    Customer customer;

    @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER, mappedBy
= "product")
    @OrderBy(value = "created DESC")
    private List<RequestLog> logs = new ArrayList<RequestLog>();
...
}

@Entity
public class RequestLog {
...
	@ManyToOne(cascade = {CascadeType.MERGE, CascadeType.REFRESH}, fetch =
FetchType.LAZY)
	@JoinColumn(name = "product_id", nullable = false)
	private Product product;

	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER, mappedBy =
"request")
	@OrderBy(value = "created DESC")
	private List<ResponseLog> children = new ArrayList<ResponseLog>();
...
}

@Entity
public class ResponseLog {
...
	@ManyToOne(cascade = {CascadeType.MERGE, CascadeType.REFRESH}, fetch =
FetchType.LAZY)
	@JoinColumn(name = "request_id", nullable = false)
	private RequestLog request;
...
}

I've noticed 2 cases of outlandish manner.

1) When I use finder for Customer or Product (with RequestLog.product using
fetchType == LAZY) I got initialized structure with all RequestLogs'
references to Products set to null

2) When I use finder for Customer or Product (with RequestLog.product using
getchType == EAGER) I see that OpenJPA generate queries to get Customer,
Product, RequestLog from DB, but queries for RequestLogs are joins using all
classes from bottom to up - (request_log, product and customer) despite the
fact, that EM has gathered these data in previous queries and could use it
instead of redundant selecting them from DB.

Is it usual OpenJPA behaviour?

-----
thanks, Beniamin 
My homesite -  http://www.mazan.pl http://www.mazan.pl 
-- 
View this message in context: http://n2.nabble.com/EAGER-vs.-LAZY-loading---weird-behaviour-in-OpenJPA-1.0.1-tp364201p364201.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.


Mime
View raw message