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