-->
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.  [ 4 posts ] 
Author Message
 Post subject: Infinite loop while merge()ing a detached object
PostPosted: Fri Mar 28, 2008 12:45 pm 
Newbie

Joined: Thu Mar 27, 2008 4:13 pm
Posts: 5
Hibernate version:

latest

Mapping documents:

Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="iwp.baseline.data.orm">
    <class name="Segmentation" table="BinderyTypeSizeAndWeightSegmentation"
           lazy="false">
        <id name="id" column="binderySizeWeightSegmentationID">
            <generator class="native" />
        </id>
        <property name="maxSheetSize" column="SheetSizeSegmentation" type="float" />
        <many-to-one name="maxPaperWeight" column="fk_paperWeightSegmentation" class="PaperWeight"/>
        <many-to-one name="binderyFunction" column="fk_binderyTypeID" class="BinderyFunction"/>
       
        <set name="binderyCosts" lazy="false"
             inverse="true" cascade="all-delete-orphan,merge">
            <key column="fk_binderySizeWeightSegmentationID"/>
            <one-to-many class="BinderyFunctionCost"/>
        </set>
    </class>
</hibernate-mapping>


and

Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="iwp.baseline.data.orm">
    <class name="BinderyFunctionCost" table="BinderyTypeCostPer1000" lazy="false">
        <composite-id>
            <key-many-to-one name="segmentation" class="Segmentation" column="fk_binderySizeWeightSegmentationID" />
            <key-many-to-one name="region" class="Region" column="fk_regionID" />
            <key-property name="quantitySegmentation" column="QuantitySegmentation" type="int" />
        </composite-id>
        <property name="costPerThousand" column="CostPer1000" type="float" />
        <property name="makeReadyCost" column="MakeReadyCost" type="float" />
        <property name="makeReadySpoilage" column="MakeReadySpoilage" type="int" />
        <property name="runSpoilage" column="RunSpoilageRate" type="float" />
    </class>
</hibernate-mapping>


Code between sessionFactory.openSession() and session.close():
Code:
Session session = getCurrentSession();
        Transaction t = session.beginTransaction();
        for (AbstractPersistentEntity<?> pe : set) {
            try {
                session.merge(pe);
            } catch (NonUniqueObjectException nuoe) {
                System.out.println("NUOE: " + nuoe.getIdentifier());
                session.merge(pe);
            }
        }
        try {
            t.commit();
        } catch (Exception e) {
            t.rollback();
            e.printStackTrace();
        }

Full stack trace of any exception that occurs:
Code:
java.lang.StackOverflowError
   at net.sourceforge.jtds.jdbc.JtdsStatement.<init>(JtdsStatement.java:129)
   at net.sourceforge.jtds.jdbc.JtdsPreparedStatement.<init>(JtdsPreparedStatement.java:96)
   at net.sourceforge.jtds.jdbc.ConnectionJDBC2.prepareStatement(ConnectionJDBC2.java:2221)
   at net.sourceforge.jtds.jdbc.ConnectionJDBC2.prepareStatement(ConnectionJDBC2.java:2179)
   at org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:505)
   at org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:423)
   at org.hibernate.jdbc.AbstractBatcher.prepareQueryStatement(AbstractBatcher.java:139)
   at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1547)
   at org.hibernate.loader.Loader.doQuery(Loader.java:673)
   at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)
   at org.hibernate.loader.Loader.loadEntity(Loader.java:1860)
   at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:48)
   at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:42)
   at org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:3049)
   at org.hibernate.event.def.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:399)
   at org.hibernate.event.def.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:375)
   at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:139)
   at org.hibernate.event.def.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:179)
   at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:103)
   at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:878)
   at org.hibernate.impl.SessionImpl.internalLoad(SessionImpl.java:846)
   at org.hibernate.type.EntityType.resolveIdentifier(EntityType.java:557)
   at org.hibernate.type.EntityType.resolve(EntityType.java:379)
   at org.hibernate.type.ComponentType.resolve(ComponentType.java:584)
   at org.hibernate.type.ComponentType.nullSafeGet(ComponentType.java:275)
   at org.hibernate.loader.Loader.getKeyFromResultSet(Loader.java:1097)
   at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:565)
   at org.hibernate.loader.Loader.doQuery(Loader.java:701)
{snip - it repeats most of the above over and over}


Name and version of the database you are using:

MSSQL Server 9.0

The generated SQL (show_sql=true):
Code:

-- this line is repeated several hundred times
Hibernate: select segmentati0_.binderySizeWeightSegmentationID as binderyS1_20_1_, segmentati0_.SheetSizeSegmentation as SheetSiz2_20_1_, segmentati0_.fk_paperWeightSegmentation as fk3_20_1_, segmentati0_.fk_binderyTypeID as fk4_20_1_, binderycos1_.fk_binderySizeWeightSegmentationID as fk1_3_, binderycos1_.fk_regionID as fk2_3_, binderycos1_.QuantitySegmentation as Quantity3_3_, binderycos1_.fk_binderySizeWeightSegmentationID as fk1_19_0_, binderycos1_.fk_regionID as fk2_19_0_, binderycos1_.QuantitySegmentation as Quantity3_19_0_, binderycos1_.CostPer1000 as CostPer4_19_0_, binderycos1_.MakeReadyCost as MakeRead5_19_0_, binderycos1_.MakeReadySpoilage as MakeRead6_19_0_, binderycos1_.RunSpoilageRate as RunSpoil7_19_0_ from BinderyTypeSizeAndWeightSegmentation segmentati0_ left outer join BinderyTypeCostPer1000 binderycos1_ on segmentati0_.binderySizeWeightSegmentationID=binderycos1_.fk_binderySizeWeightSegmentationID where segmentati0_.binderySizeWeightSegmentationID=?


Debug level Hibernate log excerpt:

none available

Any ideas? It might be that I am setting up the merge relationship incorrectly.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 31, 2008 10:11 am 
Newbie

Joined: Thu Mar 27, 2008 4:13 pm
Posts: 5
Trying one more time. Any help on this would be appreciated. I'm assuming this is not a bug, but I'm at a loss as to what I'm doing wrong here.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 31, 2008 12:49 pm 
Expert
Expert

Joined: Thu Jul 05, 2007 9:38 am
Posts: 287
I don't do XML mappings so I can just guess:

Hibernate might not identify the bidirectional mapping as such and instead of starts running in circles between the two objects.

I'd try the following:

- reduce the bidirectional mapping into an unidirectional one and check that the problem goes away.
- check the bidirectional mapping really careful, by comparing with some working example.
- If you still don't find the problem step into the Hibernate code with a debugger, to see at which point it should stop processing and why it doesn't

Jens

_________________
Please rate useful posts.


Schauderhaft: Softwaredevelopment, Projectmanagement, Qualitymanagement and all things "schauderhaft"


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 13, 2008 11:14 pm 
Beginner
Beginner

Joined: Fri May 21, 2004 5:22 am
Posts: 24
Have this problem been resolved? What was the solution?


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

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.