Return-Path: Delivered-To: apmail-ibatis-user-java-archive@www.apache.org Received: (qmail 71590 invoked from network); 18 Feb 2010 16:00:26 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 18 Feb 2010 16:00:26 -0000 Received: (qmail 37457 invoked by uid 500); 18 Feb 2010 16:00:25 -0000 Delivered-To: apmail-ibatis-user-java-archive@ibatis.apache.org Received: (qmail 37400 invoked by uid 500); 18 Feb 2010 16:00:25 -0000 Mailing-List: contact user-java-help@ibatis.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user-java@ibatis.apache.org Delivered-To: mailing list user-java@ibatis.apache.org Received: (qmail 37392 invoked by uid 99); 18 Feb 2010 16:00:25 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 18 Feb 2010 16:00:25 +0000 X-ASF-Spam-Status: No, hits=3.5 required=10.0 tests=HTML_MESSAGE,PLING_QUERY,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of clinton.begin@gmail.com designates 74.125.92.146 as permitted sender) Received: from [74.125.92.146] (HELO qw-out-1920.google.com) (74.125.92.146) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 18 Feb 2010 16:00:17 +0000 Received: by qw-out-1920.google.com with SMTP id 4so1919612qwk.60 for ; Thu, 18 Feb 2010 07:59:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :from:date:message-id:subject:to:content-type; bh=8T0e8Mnhk+P7fNLT9hVqN6vEJerqig4+kriSnctujP0=; b=TXCmG+2nEs1v+SvmyWoOrb1crzgJ/hTZ9Dy4JUV6oPztn7JFK52PbDhKHfcu9P7Cwu oGvKPxeEOQrnGAwOaLtFyLpVYqgVjoFyN5d9kMDnhZ/FB6DF4sBIZFDhjrlsG1LR0zS6 oon3P9k9+834xaxNyjtgKktcmZIGZRAREbc+0= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; b=EoVBM8daNXBmYzQJTfMolCrhHPrstwbIioyJJukGjP4HjaG6MwypdBMFAjQd532kpS cQwi9r6zOvYxXMDeh+nh0eeACDHIbhZOvRCYs+G6rzyTxbdi8jp2LEKSaCduytbNV2UR GEIyTYR8qgwXqwMBCYlwzmF/m/+BdydWWtftU= MIME-Version: 1.0 Received: by 10.224.83.85 with SMTP id e21mr2603161qal.227.1266508789264; Thu, 18 Feb 2010 07:59:49 -0800 (PST) In-Reply-To: <8017c6041002180543p2486c93fu96ef32c88a59f7d3@mail.gmail.com> References: <8017c6041002180543p2486c93fu96ef32c88a59f7d3@mail.gmail.com> From: Clinton Begin Date: Thu, 18 Feb 2010 08:59:29 -0700 Message-ID: <16178eb11002180759q2d54429aw9b82f35607cc96ed@mail.gmail.com> Subject: Re: Multiple selects per lazy loaded objects?! To: user-java@ibatis.apache.org Content-Type: multipart/alternative; boundary=000feaefa17e7fa690047fe20ea7 --000feaefa17e7fa690047fe20ea7 Content-Type: text/plain; charset=ISO-8859-2 Content-Transfer-Encoding: quoted-printable This was a topic of much debate. It does that to allow internal references to private fields. But some people don't like that behavior, so in the nex= t release (or in trunk if you want to check it out and build it), there's a configuration switch. The docs are already updated, so look for the aggressiveLazyLoad setting. Clinton 2010/2/18 Ing. Jan Novotn=FD > Hello again, > > I've found that for lazily loaded objects triggers multiple unnecessar= y > selects and are executed all at load time not at the time, when I touch t= he > property. I use 3-beta-9 and my settings are following: > > > > > > > > > > > > > > select=3D"cz.novoj.ibatis.ProductGroupMapper.getGroupById"/> > > > > > > > Test: > > @Test > public void testGetLazyProductById() throws Exception { > Product product =3D productMapper.getLazyProductById(1); > assertNotNull(product); > System.out.println("#1"); > assertEquals(1, (int)product.getId()); > System.out.println("#2"); > assertEquals("Lenovo ThinkCentre 250GB Serial ATA Hard Disk Drive= ", > product.getName()); > assertNotNull(product.getGroup()); > System.out.println("#3"); > assertEquals("HDD", product.getGroup().getName()); > assertEquals("HARDWARE", product.getGroup().getGroupType()); > assertNull(product.getTags()); > } > > Output: > > DEBUG [main][2010-02-18 14:42:34,140][java.sql.Connection]: ooo Connectio= n > Opened > DEBUG [main][2010-02-18 14:42:34,234][java.sql.PreparedStatement]: =3D=3D= > > Executing: select * from product where id =3D ? > DEBUG [main][2010-02-18 14:42:34,234][java.sql.PreparedStatement]: =3D=3D= > > Parameters: 1(Integer) > DEBUG [main][2010-02-18 14:42:34,250][java.sql.ResultSet]: <=3D=3D Col= umns: > ID, NAME, IDGROUP > DEBUG [main][2010-02-18 14:42:34,250][java.sql.ResultSet]: <=3D=3D = Row: > 1, Lenovo ThinkCentre 250GB Serial ATA Hard Disk Drive, 1 > DEBUG [main][2010-02-18 14:42:34,359][java.sql.Connection]: xxx Connectio= n > Closed > #1 > DEBUG [main][2010-02-18 14:42:34,375][java.sql.Connection]: ooo Connectio= n > Opened > DEBUG [main][2010-02-18 14:42:34,375][java.sql.PreparedStatement]: =3D=3D= > > Executing: select * from productGroup where id =3D ? > DEBUG [main][2010-02-18 14:42:34,375][java.sql.PreparedStatement]: =3D=3D= > > Parameters: 1(Integer) > DEBUG [main][2010-02-18 14:42:34,375][java.sql.ResultSet]: <=3D=3D Col= umns: > ID, NAME, GROUPTYPE > DEBUG [main][2010-02-18 14:42:34,375][java.sql.ResultSet]: <=3D=3D = Row: > 1, HDD, HARDWARE > DEBUG [main][2010-02-18 14:42:34,390][java.sql.Connection]: xxx Connectio= n > Closed > DEBUG [main][2010-02-18 14:42:34,390][java.sql.Connection]: ooo Connectio= n > Opened > DEBUG [main][2010-02-18 14:42:34,390][java.sql.PreparedStatement]: =3D=3D= > > Executing: select * from productGroup where id =3D ? > DEBUG [main][2010-02-18 14:42:34,390][java.sql.PreparedStatement]: =3D=3D= > > Parameters: 1(Integer) > DEBUG [main][2010-02-18 14:42:34,390][java.sql.ResultSet]: <=3D=3D Col= umns: > ID, NAME, GROUPTYPE > DEBUG [main][2010-02-18 14:42:34,390][java.sql.ResultSet]: <=3D=3D = Row: > 1, HDD, HARDWARE > DEBUG [main][2010-02-18 14:42:34,390][java.sql.Connection]: xxx Connectio= n > Closed > #2 > #3 > > Could someone explain how lazy really loading works? As I see, the laz= y > loading paradigm has changed a lot since iBatis 2.x > > Jan > > -- > -------------------------------------------------------------- > Ing. Jan Novotn=FD > @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ > http://blog.novoj.net > My=B9lenky dne otce Fura > -------------------------------------------------------------- > --000feaefa17e7fa690047fe20ea7 Content-Type: text/html; charset=ISO-8859-2 Content-Transfer-Encoding: quoted-printable This was a topic of much debate.=A0 It does that to allow internal referenc= es to private fields.=A0 But some people don't like that behavior, so i= n the next release (or in trunk if you want to check it out and build it), = there's a configuration switch.=A0 The docs are already updated, so loo= k for the aggressiveLazyLoad setting.

Clinton

2010/2/18 Ing. Jan Novotn=FD = <novotnaci@gmai= l.com>
Hello again,

=A0=A0 I've found that for lazily loaded objects tr= iggers multiple unnecessary selects and are executed all at load time not a= t the time, when I touch the property. I use 3-beta-9 and my settings are f= ollowing:

<settings>
=A0=A0=A0=A0=A0=A0=A0 <setting name=3D"cach= eEnabled" value=3D"true"/>
=A0=A0=A0=A0=A0=A0=A0 <s= etting name=3D"lazyLoadingEnabled" value=3D"true"/>= =A0=A0=A0=A0=A0=A0=A0
=A0=A0=A0=A0=A0=A0=A0 <setting name=3D"mu= ltipleResultSetsEnabled" value=3D"true"/>
=A0=A0=A0=A0=A0=A0=A0 <setting name=3D"useColumnLabel" value= =3D"true"/>
=A0=A0=A0=A0=A0=A0=A0 <setting name=3D"= useGeneratedKeys" value=3D"false"/>=A0=A0=A0=A0=A0=A0=A0 =
=A0=A0=A0 </settings>

<resultMap id=3D"thinProduct= LazyLoaded" type=3D"product">
=A0=A0=A0=A0=A0=A0=A0 <id property=3D"id" column=3D"id&qu= ot;/>
=A0=A0=A0=A0=A0=A0=A0 <result property=3D"name" co= lumn=3D"name"/>
=A0=A0=A0=A0=A0=A0=A0 <association prope= rty=3D"group" column=3D"idGroup" javaType=3D"group= "
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 select=3D"= ;cz.novoj.ibatis.ProductGroupMapper.getGroupById"/>
=A0=A0=A0 &l= t;/resultMap>

<select id=3D"getLazyProductById" para= meterType=3D"int" resultMap=3D"thinProductLazyLoaded"&g= t;
=A0=A0=A0=A0=A0=A0=A0 select * from product where id =3D #{id}
=A0=A0=A0= </select>

<select id=3D"getGroupById" parameterT= ype=3D"int" resultType=3D"group">
=A0=A0=A0=A0=A0= =A0=A0 select * from productGroup where id =3D #{id}
=A0=A0=A0 </select>

=A0=A0 Test:

@Test
=A0=A0=A0 pub= lic void testGetLazyProductById() throws Exception {
=A0=A0=A0 =A0=A0=A0= Product product =3D productMapper.getLazyProductById(1);
=A0=A0=A0 =A0= =A0=A0 assertNotNull(product);
=A0=A0=A0 =A0=A0=A0 System.out.println(&q= uot;#1");
=A0=A0=A0 =A0=A0=A0 assertEquals(1, (int)product.getId());
=A0=A0=A0 =A0= =A0=A0 System.out.println("#2");
=A0=A0=A0 =A0=A0=A0 assertEqu= als("Lenovo ThinkCentre 250GB Serial ATA Hard Disk Drive", produc= t.getName());
=A0=A0=A0 =A0=A0=A0 assertNotNull(product.getGroup());
=A0=A0=A0 =A0=A0=A0 System.out.println("#3");
=A0=A0=A0 =A0=A0= =A0 assertEquals("HDD", product.getGroup().getName());
=A0=A0= =A0 =A0=A0=A0 assertEquals("HARDWARE", product.getGroup().getGrou= pType());
=A0=A0=A0 =A0=A0=A0 assertNull(product.getTags());
=A0=A0=A0 }

=A0=A0 Output:

DEBUG [main][2010-02-18 14:42:34,1= 40][java.sql.Connection]: ooo Connection Opened
DEBUG [main][2010-02-18 = 14:42:34,234][java.sql.PreparedStatement]: =3D=3D>=A0 Executing: select = * from product where id =3D ?
DEBUG [main][2010-02-18 14:42:34,234][java.sql.PreparedStatement]: =3D=3D&g= t; Parameters: 1(Integer)
DEBUG [main][2010-02-18 14:42:34,250][java.sql= .ResultSet]: <=3D=3D=A0=A0=A0 Columns: ID, NAME, IDGROUP
DEBUG [main]= [2010-02-18 14:42:34,250][java.sql.ResultSet]: <=3D=3D=A0=A0=A0=A0=A0=A0= =A0 Row: 1, Lenovo ThinkCentre 250GB Serial ATA Hard Disk Drive, 1
DEBUG [main][2010-02-18 14:42:34,359][java.sql.Connection]: xxx Connection = Closed
#1
DEBUG [main][2010-02-18 14:42:34,375][java.sql.Connection]:= ooo Connection Opened
DEBUG [main][2010-02-18 14:42:34,375][java.sql.Pr= eparedStatement]: =3D=3D>=A0 Executing: select * from productGroup where= id =3D ?
DEBUG [main][2010-02-18 14:42:34,375][java.sql.PreparedStatement]: =3D=3D&g= t; Parameters: 1(Integer)
DEBUG [main][2010-02-18 14:42:34,375][java.sql= .ResultSet]: <=3D=3D=A0=A0=A0 Columns: ID, NAME, GROUPTYPE
DEBUG [mai= n][2010-02-18 14:42:34,375][java.sql.ResultSet]: <=3D=3D=A0=A0=A0=A0=A0= =A0=A0 Row: 1, HDD, HARDWARE
DEBUG [main][2010-02-18 14:42:34,390][java.sql.Connection]: xxx Connection = Closed
DEBUG [main][2010-02-18 14:42:34,390][java.sql.Connection]: ooo C= onnection Opened
DEBUG [main][2010-02-18 14:42:34,390][java.sql.Prepared= Statement]: =3D=3D>=A0 Executing: select * from productGroup where id = =3D ?
DEBUG [main][2010-02-18 14:42:34,390][java.sql.PreparedStatement]: =3D=3D&g= t; Parameters: 1(Integer)
DEBUG [main][2010-02-18 14:42:34,390][java.sql= .ResultSet]: <=3D=3D=A0=A0=A0 Columns: ID, NAME, GROUPTYPE
DEBUG [mai= n][2010-02-18 14:42:34,390][java.sql.ResultSet]: <=3D=3D=A0=A0=A0=A0=A0= =A0=A0 Row: 1, HDD, HARDWARE
DEBUG [main][2010-02-18 14:42:34,390][java.sql.Connection]: xxx Connection = Closed
#2
#3

=A0=A0 Could someone explain how lazy really load= ing works? As I see, the lazy loading paradigm has changed a lot since iBat= is 2.x

Jan

--
---------------= -----------------------------------------------
Ing. Jan Novotn=FD
@@= @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
http://blog.novoj.net
My=B9lenky dne otce Fura
-----------------------------------------------= ---------------

--000feaefa17e7fa690047fe20ea7--