Return-Path: Delivered-To: apmail-openjpa-users-archive@locus.apache.org Received: (qmail 67704 invoked from network); 11 Sep 2007 07:54:48 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 11 Sep 2007 07:54:48 -0000 Received: (qmail 27121 invoked by uid 500); 11 Sep 2007 07:54:41 -0000 Delivered-To: apmail-openjpa-users-archive@openjpa.apache.org Received: (qmail 27094 invoked by uid 500); 11 Sep 2007 07:54:41 -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 27085 invoked by uid 99); 11 Sep 2007 07:54:41 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 11 Sep 2007 00:54:41 -0700 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of plinskey@gmail.com designates 209.85.146.183 as permitted sender) Received: from [209.85.146.183] (HELO wa-out-1112.google.com) (209.85.146.183) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 11 Sep 2007 07:54:39 +0000 Received: by wa-out-1112.google.com with SMTP id m28so2041440wag for ; Tue, 11 Sep 2007 00:54:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; bh=RMzF8dModZzV6Xm4C7ibxmljot46AsXrbU+MBIcHtuI=; b=UfR2L3arRU0bksuiIAOpqQA2SSm4qHEBB+s0O7d35sd2md6D0ZafB0kYvyZezACieIz830a4xUqS5JFuHlKO0rG8E29hhjjqOr9WP0/+fa8hLdaOLucDYj72SJU5h7ZLROgBNQvt+iwh5xY80X816Jk0S7KYJEOC9XKDn9vO6JI= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=nnwBWo/4VuV2aKe9e6bmFrvFTNBUKwHWG58ODbGOVoWxch0mlLlH9cGSmO0hcj5H6t4pk/jGpF/WhF5+s2G2AnIsC1OztJ0In/0nffg2RDRyGbKEgnEeEqlaEalNIDrGPJoIsudQfaVSCd34JwXWLRxB5BsPhL4opvoQCCa03Ro= Received: by 10.142.153.8 with SMTP id a8mr275023wfe.1189497258757; Tue, 11 Sep 2007 00:54:18 -0700 (PDT) Received: by 10.143.16.2 with HTTP; Tue, 11 Sep 2007 00:54:18 -0700 (PDT) Message-ID: <7262f25e0709110054m7bdd524dk1c44f79cf798d5b7@mail.gmail.com> Date: Tue, 11 Sep 2007 00:54:18 -0700 From: "Patrick Linskey" To: users@openjpa.apache.org Subject: Re: Lazy load for detached entities In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: X-Virus-Checked: Checked by ClamAV on apache.org Hi, Lazy loading is not available for detached entities -- by definition, they are no longer associated with the database. You can, however, control whether OpenJPA returns null or throws an exception when an unloaded field is accessed. If you want to be able to lazily access a field after a transaction completes, you might want to consider keeping the entity manager open for the duration of your request. -Patrick On 9/11/07, Evgeny Shepelyuk wrote: > Hello ! > > Is there any way to access fields marked with lazy fetching for detached > entities. > Im having some code like > > @Entity > @Table(schema = "public", name = "users") > public class UsersEntity { > private Integer userid; > private List orders; > > @OneToMany(cascade = CascadeType.PERSIST, mappedBy = "user", fetch = > FetchType.LAZY) > public List getOrders() { > return orders; > } > > public void setOrders(List orders) { > this.orders = orders; > } > > @Id > @Column(name = "userid", nullable = false) > @GeneratedValue(strategy = GenerationType.IDENTITY) > public Integer getUserid() { > return userid; > } > > public void setUserid(Integer userid) { > this.userid = userid; > } > } > > > @Entity > @Table(schema = "public", name = "orders") > public class OrdersEntity { > private Integer orderid; > private UsersEntity user; > > @ManyToOne(fetch = FetchType.LAZY) > @JoinColumn(name = "userid", nullable = false) > public UsersEntity getUser() { > return user; > } > > public void setUser(UsersEntity user) { > this.user = user; > } > > @Id > @Column(name = "orderid", nullable = false, length = 10) > @GeneratedValue(strategy = GenerationType.IDENTITY) > public Integer getOrderid() { > return orderid; > } > > public void setOrderid(Integer orderid) { > this.orderid = orderid; > } > } > > And my program code > > EntityManagerFactory emf = Persistence.createEntityManagerFactory("pu1"); > EntityManager em = emf.createEntityManager(); > OrdersEntity order = em.find(OrdersEntity.class, .....); > em.close(); > System.out.println(order.getUser()); > emf.close(); > > And it shows null. > -- > Best Regards > Evgeny K. Shepelyuk > -- Patrick Linskey 202 669 5907