Return-Path: Delivered-To: apmail-openjpa-users-archive@minotaur.apache.org Received: (qmail 818 invoked from network); 18 Feb 2011 09:26:27 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 18 Feb 2011 09:26:27 -0000 Received: (qmail 16080 invoked by uid 500); 18 Feb 2011 09:26:27 -0000 Delivered-To: apmail-openjpa-users-archive@openjpa.apache.org Received: (qmail 15804 invoked by uid 500); 18 Feb 2011 09:26:24 -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 15777 invoked by uid 99); 18 Feb 2011 09:26:23 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 18 Feb 2011 09:26:23 +0000 X-ASF-Spam-Status: No, hits=-0.0 required=5.0 tests=RCVD_IN_DNSWL_NONE,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: local policy) Received: from [194.109.24.31] (HELO smtp-vbr11.xs4all.nl) (194.109.24.31) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 18 Feb 2011 09:26:14 +0000 Received: from remote.huizemolenaar.nl (D57D0452.static.ziggozakelijk.nl [213.125.4.82]) (authenticated bits=0) by smtp-vbr11.xs4all.nl (8.13.8/8.13.8) with ESMTP id p1I9PsGR079948 (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=FAIL) for ; Fri, 18 Feb 2011 10:25:54 +0100 (CET) (envelope-from henno@huizemolenaar.nl) Received: from HMS.hm.local ([fe80::6051:4a91:4c0d:d963]) by HMS.hm.local ([fe80::6051:4a91:4c0d:d963%10]) with mapi; Fri, 18 Feb 2011 10:25:38 +0100 From: Henno Vermeulen To: "'users@openjpa.apache.org'" Date: Fri, 18 Feb 2011 10:25:36 +0100 Subject: RE: N+1 select problem for Map no matter what I try Thread-Topic: N+1 select problem for Map no matter what I try Thread-Index: AcvOv3zFOi6xz1tYRlqQ3XNYXSM3SQAjfPow Message-ID: <1C448C478A6B4743AF19DBC3C3DCE1320141807D8CA7@HMS.hm.local> References: <1C448C478A6B4743AF19DBC3C3DCE132014180635A86@HMS.hm.local> <1C448C478A6B4743AF19DBC3C3DCE1320141807D8C17@HMS.hm.local> <1C448C478A6B4743AF19DBC3C3DCE1320141807D8C67@HMS.hm.local> In-Reply-To: Accept-Language: nl-NL Content-Language: nl-NL X-MS-Has-Attach: X-MS-TNEF-Correlator: acceptlanguage: nl-NL Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-Virus-Scanned: by XS4ALL Virus Scanner X-Virus-Checked: Checked by ClamAV on apache.org Alright, thank you for looking into it. I will use a List of Entities that = contain the key and value and see if performance is better. Henno -----Oorspronkelijk bericht----- Van: Rick Curtis [mailto:curtisr7@gmail.com]=20 Verzonden: donderdag 17 februari 2011 17:27 Aan: users@openjpa.apache.org Onderwerp: Re: N+1 select problem for Map no matter what I try Heno - It looks like this is the expected behavior. Keep an eye on OPENJPA-1920 fo= r any changes that we may try to make in this area. Thanks, Rick On Thu, Feb 17, 2011 at 8:37 AM, Henno Vermeulen wr= ote: > That's great, thank you for your time! > > Heno > > -----Oorspronkelijk bericht----- > Van: Rick Curtis [mailto:curtisr7@gmail.com] > Verzonden: donderdag 17 februari 2011 15:36 > Aan: users@openjpa.apache.org > Onderwerp: Re: N+1 select problem for Map no matter what I try > > Ok, now I was able to recreate the behavior that you reported... I'll dig > into this a little more and get back with you. > > Thanks, > Rick > > On Thu, Feb 17, 2011 at 4:25 AM, Henno Vermeulen >wrote: > > > Thank you for your reply! I tried and it unfortunately doesn't work. I > > stripped my example down to the bare minimum. I am using OpenJPA 2.0.0 > > (downloaded openjpa-all using Maven). > > In my real application I use compile time enhancement and mssql server,= I > > am running this test with hsqldb and openjpa as javaagent > > > (-javaagent:C:/Users/h.vermeulen/.m2/repository/org/apache/openjpa/openjp= a-all/2.0.0/openjpa-all-2.0.0.jar). > > > > Here are my classes and settings: > > > > Persistence.xml: > > > xmlns:xsi=3D"http://www.w3.org/2001/XMLSchema-instance" > > xsi:schemaLocation=3D" > http://java.sun.com/xml/ns/persistencepersistence_1_0.xsd" > > version=3D"1.0"> > > > > > > > > org.apache.openjpa.persistence.PersistenceProviderImpl > > > > entities.TestEntity > > true > > > > > value=3D"buildSchema" /> > > > value=3D"org.hsqldb.jdbcDriver" /> > > > value=3D"jdbc:hsqldb:mem:test" /> > > > value=3D"sa" /> > > value=3D"" > > /> > > > value=3D"DefaultLevel=3DTRACE" /> > > > > > > > > > > TestEntity.java: > > package entities; > > > > import java.util.HashMap; > > import java.util.Map; > > > > import javax.persistence.CascadeType; > > import javax.persistence.Entity; > > import javax.persistence.FetchType; > > import javax.persistence.GeneratedValue; > > import javax.persistence.Id; > > > > import org.apache.openjpa.persistence.PersistentMap; > > > > @Entity > > public class TestEntity { > > > > @Id > > @GeneratedValue > > private Long id; > > > > @PersistentMap(elementCascade =3D CascadeType.PERSIST, fetch =3D > > FetchType.EAGER) > > private Map strings =3D new HashMap > String>(); > > > > public TestEntity() { > > } > > > > public Long getId() { > > return id; > > } > > > > public Map getStrings() { > > return strings; > > } > > > > } > > > > MapPerformanceTest.java: > > import java.util.List; > > > > import javax.persistence.EntityManagerFactory; > > import javax.persistence.Persistence; > > > > import org.apache.openjpa.persistence.OpenJPAEntityManager; > > > > import entities.TestEntity; > > > > public class MapPerformanceTest { > > private EntityManagerFactory factory; > > > > public void createEntityManagerFactory() { > > factory =3D Persistence.createEntityManagerFactory("test= PU", > > System > > .getProperties()); > > } > > > > private void persistInTransaction(TestEntity item) { > > OpenJPAEntityManager em =3D (OpenJPAEntityManager) facto= ry > > .createEntityManager(); > > em.getTransaction().begin(); > > em.persist(item); > > em.getTransaction().commit(); > > em.close(); > > } > > > > private void createEntities() { > > for (int i =3D 0; i < 100; i++) { > > TestEntity entity =3D new TestEntity(); > > entity.getStrings().put("a", "test " + i); > > entity.getStrings().put("b", "another test " + i= ); > > persistInTransaction(entity); > > } > > } > > > > private List findAllEntities() { > > OpenJPAEntityManager em =3D (OpenJPAEntityManager) facto= ry > > .createEntityManager(); > > em.getTransaction().begin(); > > String query =3D "SELECT z FROM " + > > TestEntity.class.getSimpleName() > > + " z"; > > List result =3D em.createQuery(query, > > TestEntity.class) > > .getResultList(); > > em.getTransaction().commit(); > > em.close(); > > return result; > > } > > > > public static void main(String[] args) { > > MapPerformanceTest t =3D new MapPerformanceTest(); > > t.createEntityManagerFactory(); > > t.createEntities(); > > System.err.println("----------- find all -----------"); > > t.findAllEntities(); > > } > > } > > > > > > Henno Vermeulen > > > > -----Oorspronkelijk bericht----- > > Van: Rick Curtis [mailto:curtisr7@gmail.com] > > Verzonden: woensdag 16 februari 2011 16:49 > > Aan: users@openjpa.apache.org > > Onderwerp: Re: N+1 select problem for Map no matter what I try > > > > Can you try using @PersistentMap(elementCascade =3D > > CascadeType.PERSIST,fetch=3DFetchType.EAGER) rather than > @ElementCollection? > > I > > don't see the N+1 select problem in my tests when using the persistentm= ap > > annotation. > > > > Thanks, > > Rick > > > > On Wed, Feb 16, 2011 at 8:36 AM, Henno Vermeulen > >wrote: > > > > > When I have a Map inside a TestEntity (mapped either with @OneToMany = or > > > @ElementCollection), OpenJPA 2 always performs N + 1 selects when I d= o > > the > > > simple query "SELECT z FROM TestEntity z". > > > > > > A solution to this would of course be great, but I would also be very > > happy > > > if an OpenJPA developer could quickly try this out and confirm to me > > whether > > > or not this is indeed an issue with OpenJPA or that it is simply > expected > > > behavior. > > > > > > Regards, > > > Henno Vermeulen > > > > > > (p.s. I have tried many settings and the problem occurs no matter wha= t > I > > > try. See https://issues.apache.org/jira/browse/OPENJPA-1920 and my > > > unanswered post "preventing N+1 select performance problem on maps"). > > > > > > > > >