Return-Path: Delivered-To: apmail-openjpa-users-archive@locus.apache.org Received: (qmail 35076 invoked from network); 8 Jul 2008 11:57:11 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 8 Jul 2008 11:57:11 -0000 Received: (qmail 84492 invoked by uid 500); 8 Jul 2008 11:57:11 -0000 Delivered-To: apmail-openjpa-users-archive@openjpa.apache.org Received: (qmail 84474 invoked by uid 500); 8 Jul 2008 11:57:11 -0000 Mailing-List: contact users-help@openjpa.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: users@openjpa.apache.org Delivered-To: mailing list users@openjpa.apache.org Received: (qmail 84463 invoked by uid 99); 8 Jul 2008 11:57:11 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 08 Jul 2008 04:57:11 -0700 X-ASF-Spam-Status: No, hits=0.2 required=10.0 tests=SPF_HELO_PASS,SPF_PASS,WHOIS_MYPRIVREG X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of lists+1214986160035-208411@n2.nabble.com designates 216.139.236.158 as permitted sender) Received: from [216.139.236.158] (HELO kuber.nabble.com) (216.139.236.158) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 08 Jul 2008 11:56:15 +0000 Received: from isper.nabble.com ([192.168.236.156]) by kuber.nabble.com with esmtp (Exim 4.63) (envelope-from ) id 1KGBoC-0004G0-50 for users@openjpa.apache.org; Tue, 08 Jul 2008 04:56:36 -0700 Message-ID: <1215518196063-364201.post@n2.nabble.com> Date: Tue, 8 Jul 2008 04:56:36 -0700 (PDT) From: Beniamin Mazan To: users@openjpa.apache.org Subject: EAGER vs. LAZY loading - weird behaviour in OpenJPA 1.0.1 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Nabble-From: it@mazan.pl X-Virus-Checked: Checked by ClamAV on apache.org 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 products = new HashSet(); ... } @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 logs = new ArrayList(); ... } @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 children = new ArrayList(); ... } @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.