lazy-loading

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

lazy-loading

Vogon
Hi guys,

How does lazy-loading work in MyBatis?

For example :


public static void main(String args[]){

        SqlSession session = iBATISUtilsXML.getSession();

        List<Bid>bids = (List<Bid>)session.selectList("getAllBids");

        for(Bid bid : bids){
           System.out.println("Identifier : "+bid.getId());
           System.out.println("Amount     :"+bid.getAmount());
        }

        session.close();

        }





with this mapping:



        <resultMap id="bidMapper" type="Bid">

             <id     property="id"         column="BID_ID"/>

             <result property="amount"     column="amount"/>

             <result property="created"    column="created"/>

             <association property="item"  column="ITEM_ID"
javaType="Item" select="readItem"/>

        </resultMap>



    <select id="getAllBids" resultMap="bidMapper">

       select * from BID

    </select>




with any combination of   <setting name="aggressiveLazyLoading"
value="true"/>
and <setting name="lazyLoadingEnabled" value="true"/>  in my
Configuration.xml

iBATIS ALWAYS performs an extra-select to retrieve Item object :

    DEBUG PreparedStatement:28 - ==>  Executing: select * from ITEM
where ITEM_ID=?

I don't want this extra-select, because  I didn't access the property
"item"  in any way.

How can I do ?