-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: how to load the *content of* a collection in lazy mode?
PostPosted: Mon Nov 03, 2008 3:28 pm 
Newbie

Joined: Sun May 25, 2008 9:02 am
Posts: 6
Hi,

I have a table called "projects". Each project has a list of "developers".
Only for the sake of the example, a particular project has more than 100.000 developers,
and I want to add one more developer to this list.

I do like this:

Code:
Session session = sessionFactory.openSession();
Transaction tx = session.beginTransaction();

Map<String, Object> project = (Map<String, Object>) session.load("Project", (long) 1);
List<Map<String, Object>> developers = (List<Map<String, Object>>) project.get("developers");   //***1. this works ok.
           

developers.add(createDeveloper());
//***2. if the project has few developers, this works ok.
//however, if the project has 100.000 developers, this fires java.lang.OutOfMemoryError: Java heap space


tx.commit();
session.close();



Code:
<hibernate-mapping>
    <class entity-name="Project" table="project">
        <id name="id" column="id" type="long">
            <generator class="native" />
        </id>
        <property name="projectName" type="string" index="projectName" />

        <list name="developers" table="Developer" lazy="true" cascade="all">   ***3.
            <key column="projectId"/>
            <list-index column="position"/>
            <one-to-many class="Developer"/>
        </list>
    </class>

    <class entity-name="Developer" table="developer">
        <id name="id" column="id" type="long"><generator class="native" /></id>
        <property name="firstName" type="string" index="firstName" />
        <property name="lastName" type="string" index="lastName" />
    </class>
</hibernate-mapping>



I've tried ***3 with lazy = "false", "true" or "extra".
but it has exactly the same result.

it seems that when I call developers.add(createDeveloper()); ***2.
it loads the list of 100.000 developers in memory!!!
why? I only want to add one developer to the list.

do you see a way to solve this?


Regards,
DAvid


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.