-->
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: Dynamic-map entity mode - StackOverflow
PostPosted: Fri Mar 09, 2007 7:24 am 
Newbie

Joined: Thu Mar 08, 2007 11:33 am
Posts: 1
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

I try to use Hibernate in dynamic-map entity mode, with bidirectional one-to-many relationship. But when I would like to save the parent object, the hibernate throws StackOverflowError exception.
But when I debug the hibernate source I found that getSanpshot method in the PersistentSet class try to clone the Set into a HashMap. However if the original Set has HashMap values, the method try to store this values with following procedure:

...
HashMap clonedSet = new HashMap( set.size() );
Iterator iter = set.iterator();
while ( iter.hasNext() ) {
Object copied = persister.getElementType().deepCopy( iter.next(), entityMode, persister.getFactory() );
clonedSet.put(copied, copied);
}
...

The new HashMap item key and value is same HashMap. When the Java try to determine hashCode an StackOverflowError exception generates.

I use the folowing code. How can I resolve this situation?

Roland

Hibernate version: 3.2.2

Mapping documents:

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated 2007.03.08. 9:02:32 by Hibernate Tools 3.2.0.b9 -->
<hibernate-mapping>
<class entity-name="BelsoKaranten" table="BELSO_KARANTEN">
<id name="belsoKarantenId" type="long">
<column name="BELSO_KARANTEN_ID" precision="10" scale="0" />
<generator class="sequence">
<param name="sequence">seq_global</param>
</generator>
</id>
<property name="megyeId" type="long">
<column name="MEGYE_ID" precision="10" scale="0" not-null="true" />
</property>
<property name="vizsgKozegId" type="long">
<column name="VIZSG_KOZEG_ID" precision="10" scale="0" not-null="true" />
</property>
<property name="vizsgDatum" type="date">
<column name="VIZSG_DATUM" length="7" not-null="true" />
</property>
<property name="pecsetszam" type="string">
<column name="PECSETSZAM" length="10" />
</property>
<property name="vizsgalatHelye" type="string">
<column name="VIZSGALAT_HELYE" />
</property>
<property name="ugyfelId" type="java.lang.Long">
<column name="UGYFEL_ID" precision="10" scale="0" />
</property>
<set name="vizsgaltObjektums" inverse="true" cascade="all">
<key>
<column name="BELSO_KARANTEN_ID" precision="10" scale="0" not-null="true" />
</key>
<one-to-many class="VizsgaltObjektum" />
</set>
</class>
</hibernate-mapping>

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated 2007.03.08. 9:02:32 by Hibernate Tools 3.2.0.b9 -->
<hibernate-mapping>
<class entity-name="VizsgaltObjektum" table="VIZSGALT_OBJEKTUM">
<id name="vizsgObjId" type="long">
<column name="VIZSG_OBJ_ID" precision="10" scale="0" />
<generator class="sequence">
<param name="sequence">seq_global</param>
</generator>
</id>
<many-to-one name="belsoKaranten" class="BelsoKaranten" fetch="select">
<column name="BELSO_KARANTEN_ID" precision="10" scale="0" not-null="true" />
</many-to-one>
<property name="proba1" type="string">
<column name="PROBA1" />
</property>
<property name="proba2" type="string">
<column name="PROBA2" />
</property>
</class>
</hibernate-mapping>

Code between sessionFactory.openSession() and session.close():

private void tryHibernate() {
Session s = HibernateUtil.currentSession();
Transaction tx = s.beginTransaction();

Map<Object, Object> belsoKaranten = new HashMap<Object, Object>();
Set set = new HashSet();
belsoKaranten.put("megyeId", new Long(3));
belsoKaranten.put("vizsgKozegId", new Long (3));
belsoKaranten.put("vizsgDatum", new Date(System.currentTimeMillis()));
belsoKaranten.put("pecsetszam", "0123456789");
belsoKaranten.put("vizsgalatHelye", "vizsgalatHelye");
belsoKaranten.put("ugyfelId", new Long(3));
belsoKaranten.put("vizsgaltObjektums", set);

Map<Object, Object> vizsgaltObjektum = new HashMap<Object, Object>();
vizsgaltObjektum.put("belsoKaranten", belsoKaranten);
vizsgaltObjektum.put("proba1", "proba1");
vizsgaltObjektum.put("proba2", "proba2");
set.add(vizsgaltObjektum);

Map<Object, Object> vizsgaltObjektum2 = new HashMap<Object, Object>();
vizsgaltObjektum2.put("belsoKaranten", belsoKaranten);
vizsgaltObjektum2.put("proba1", "proba1");
vizsgaltObjektum2.put("proba2", "proba2");
set.add(vizsgaltObjektum2);

s.save("BelsoKaranten", belsoKaranten);
tx.commit();
s.close();
}

Full stack trace of any exception that occurs:

Name and version of the database you are using:
Oracle 10

Debug level Hibernate log excerpt:

Read this: http://hibernate.org/42.html

_________________
Roland


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.