Return-Path: Delivered-To: apmail-openjpa-users-archive@locus.apache.org Received: (qmail 38113 invoked from network); 8 Jul 2008 12:04:16 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 8 Jul 2008 12:04:16 -0000 Received: (qmail 91970 invoked by uid 500); 8 Jul 2008 12:04:17 -0000 Delivered-To: apmail-openjpa-users-archive@openjpa.apache.org Received: (qmail 91945 invoked by uid 500); 8 Jul 2008 12:04:17 -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 91934 invoked by uid 99); 8 Jul 2008 12:04:17 -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 05:04:17 -0700 X-ASF-Spam-Status: No, hits=2.2 required=10.0 tests=HTML_MESSAGE,SPF_PASS,WHOIS_MYPRIVREG X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of plunchete@gmail.com designates 66.249.92.175 as permitted sender) Received: from [66.249.92.175] (HELO ug-out-1314.google.com) (66.249.92.175) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 08 Jul 2008 12:03:22 +0000 Received: by ug-out-1314.google.com with SMTP id z34so1953437ugc.42 for ; Tue, 08 Jul 2008 05:03:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to :subject:in-reply-to:mime-version:content-type:references; bh=amogWFhdkZvN28+FZcW88+JdpYQRSy5IccE4Fhaas2g=; b=OtTsL+QjPu4aNVpF6Y9lKaR9QFgNw5clWXWswyKj4OfJaG7C6EaImSQyyxauMCcN3h 8WorFEnb1hAPmux/RsBRKYzh9THCoZisYwvNrqDWdM8UO+Et7BZFjez/sFCHU6s4oKKd e3BdB2AMCYIhrYZtN+RDC/Rdm1hCC2nW7N1QQ= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:in-reply-to:mime-version :content-type:references; b=dDg336hXpI+KsAfMJq9XeubuKDCP37jP8yiB98b1bPWJf5H3BfWkBuB7eEQL2M86Mi zywXbkG0+VemBtVu6KYWYJqJOR3sVZQ6Ii9lQ35x2UBTXR6WiaaL2LbXp4Y5m1S3R8zE kg+sKJNOwKzi9KhbcZT5p9nB32lIgI6h+TrU4= Received: by 10.67.24.11 with SMTP id b11mr5315036ugj.35.1215518622599; Tue, 08 Jul 2008 05:03:42 -0700 (PDT) Received: by 10.66.236.14 with HTTP; Tue, 8 Jul 2008 05:03:42 -0700 (PDT) Message-ID: <41fba98d0807080503s238b80a9k5eb432903abce460@mail.gmail.com> Date: Tue, 8 Jul 2008 14:03:42 +0200 From: "Ignacio Andreu" To: users@openjpa.apache.org Subject: Re: EAGER vs. LAZY loading - weird behaviour in OpenJPA 1.0.1 In-Reply-To: <1215518196063-364201.post@n2.nabble.com> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_15529_23245397.1215518622619" References: <1215518196063-364201.post@n2.nabble.com> X-Virus-Checked: Checked by ClamAV on apache.org ------=_Part_15529_23245397.1215518622619 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline As far as I know, if you use the eager strategy is normal that OpenJPA generates queries to load the diferent relations from the database. If you use lazy strategy OpenJPA only loads the relations when they are acceded, of course if you are handling the PersistentContext for your own and you closed it before the access it will be null. On Tue, Jul 8, 2008 at 1:56 PM, Beniamin Mazan wrote: > > 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. > > ------=_Part_15529_23245397.1215518622619--