-->
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: Problem with Persistent Set in Persistent Set
PostPosted: Fri Nov 24, 2006 6:09 am 
Newbie

Joined: Thu Sep 08, 2005 3:45 am
Posts: 4
Hibernate version:
3.2.1

Mapping documents:
Code:
<hibernate-mapping>
    <class
        name="at.sozvers.hvb.pkt.model.versicherter.VersicherterBE"
        table="VERSICHERTER"
        schema="PKTDB">

        <id
            name="vsnr"
            column="vsnr"
            type="java.lang.String"
            length="10">
            <generator class="assigned">
            </generator>
        </id>

        <version
            name="version"
            column="version"
            type="long"
        />
       
        <!-- a few normal property mappings here -->
        <property ... />


        <set
            name="versicherungsverhaeltnisse"
            lazy="true"
            inverse="true"
            cascade="all-delete-orphan"
            sort="unsorted"
            batch-size="100">

            <key
                column="vsnr">
            </key>

            <one-to-many
                  class="at.sozvers.hvb.pkt.model.versicherungsverhaeltnis.VersicherungsverhaeltnisBE"
            />

        </set>
    </class>
   
   
   
    <class
        name="at.sozvers.hvb.pkt.model.versicherungsverhaeltnis.VersicherungsverhaeltnisBE"
        table="VERSICHERUNGSVERHAELTNIS"
        schema="PKTDB">

        <id
            name="id"
            column="id"
            type="java.lang.Long">
            <generator class="native">
            </generator>
        </id>

        <version
            name="version"
            column="version"
            type="long"
        />

        <many-to-one
            name="versicherter"
            class="at.sozvers.hvb.pkt.model.versicherter.VersicherterBE"
            cascade="none"
            outer-join="auto"
            update="true"
            insert="true"
            foreign-key="FK_VVH_VERSICHERTER"
        >
            <column
                name="vsnr"
                index="vvh_vsnr_idx"
                not-null="true"
            />
        </many-to-one>
       
               
        <!-- a few normal property mappings here -->
        <property ... />

        <set
            name="beitragsgrundlagen"
            lazy="true"
            inverse="true"
            cascade="all-delete-orphan"
            sort="unsorted"
            batch-size="50">

            <key
                column="vvh">
            </key>

            <one-to-many
                  class="at.sozvers.hvb.pkt.model.versicherungsverhaeltnis.BeitragsgrundlageBE"
            />

        </set>
    </class>
   
   
    <class
        name="at.sozvers.hvb.pkt.model.versicherungsverhaeltnis.BeitragsgrundlageBE"
        table="BEITRAGSGRUNDLAGE"
        schema="PKTDB">

        <id
            name="id"
            column="id"
            type="java.lang.Long">
            <generator class="native">
            </generator>
        </id>

        <many-to-one
            name="vvh"
            class="at.sozvers.hvb.pkt.model.versicherungsverhaeltnis.VersicherungsverhaeltnisBE"
            cascade="none"
            outer-join="auto"
            update="true"
            insert="true"
            foreign-key="FK_BG_VVH"
        >
            <column
                name="vvh"
                index="beitragsgrundlage_vvh_idx"
                not-null="true"
            />
        </many-to-one>
       
       
        <many-to-one
            name="versicherter"
            class="at.sozvers.hvb.pkt.model.versicherter.VersicherterBE"
            cascade="none"
            outer-join="auto"
            update="true"
            insert="true"
            foreign-key="FK_BG_VERSICHERTER"
        >
            <column
                name="vsnr"
                index="beitragsgrundlage_vsnr_idx"
                not-null="true"
            />
        </many-to-one>

       
        <!-- a few normal property mappings here -->
        <property ... />

    </class>
   
</hibernate-mapping>



Code between sessionFactory.openSession() and session.close():
Code:
/* If I don't do the flush I get the exception below! */
// session.flush;
Query query = session.getNamedQuery(queryName);
query.setParameter(_KZ, kz);
query.setParameter(_KEY, key);
return query.uniqueResult();


Full stack trace of any exception that occurs:
Code:
org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing: at.sozvers.hvb.pkt.model.versicherungsverhaeltnis.VersicherungsverhaeltnisBE
   at org.hibernate.engine.ForeignKeys.getEntityIdentifierIfNotUnsaved(ForeignKeys.java:219)
   at org.hibernate.type.EntityType.getIdentifier(EntityType.java:397)
   at org.hibernate.type.ManyToOneType.isDirty(ManyToOneType.java:242)
   at org.hibernate.type.TypeFactory.findDirty(TypeFactory.java:563)
   at org.hibernate.persister.entity.AbstractEntityPersister.findDirty(AbstractEntityPersister.java:3071)
   at org.hibernate.event.def.DefaultFlushEntityEventListener.dirtyCheck(DefaultFlushEntityEventListener.java:472)
   at org.hibernate.event.def.DefaultFlushEntityEventListener.isUpdateNecessary(DefaultFlushEntityEventListener.java:197)
   at org.hibernate.event.def.DefaultFlushEntityEventListener.onFlushEntity(DefaultFlushEntityEventListener.java:120)
   at org.hibernate.event.def.AbstractFlushingEventListener.flushEntities(AbstractFlushingEventListener.java:196)
   at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:76)
   at org.hibernate.event.def.DefaultAutoFlushEventListener.onAutoFlush(DefaultAutoFlushEventListener.java:35)
   at org.hibernate.impl.SessionImpl.autoFlushIfRequired(SessionImpl.java:969)
   at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1114)
   at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
   at org.hibernate.impl.AbstractQueryImpl.uniqueResult(AbstractQueryImpl.java:804)
   at at.sozvers.hvb.pkt.dao.impl.hibernate.PKTConstantsDAOImpl$RegelBEMitMeldenderStelleHibernateCallback.doInHibernate(PKTConstantsDAOImpl.java:493)
   at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:358)
   at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:331)
   at at.sozvers.hvb.pkt.dao.impl.hibernate.PKTConstantsDAOImpl.getRegelBeMitMeldenderStelle(PKTConstantsDAOImpl.java:354)
   at at.sozvers.hvb.pkt.dao.impl.hibernate.PKTConstantsDAOImpl.findRegel(PKTConstantsDAOImpl.java:372)
   at at.sozvers.hvb.pkt.dao.impl.hibernate.PKTConstantsDAOImpl.findRegelMitSteuerfeld(PKTConstantsDAOImpl.java:350)
   at at.sozvers.hvb.pkt.dao.impl.delegate.DelegateConstantsDAOImpl.findRegelMitSteuerfeld(DelegateConstantsDAOImpl.java:132)
   at at.sozvers.hvb.pkt.util.PktVersicherungsverlauf.loadRule(PktVersicherungsverlauf.java:68)
   at at.sozvers.hvb.pkt.util.PktVersicherungsverlauf.loadRuleForElement(PktVersicherungsverlauf.java:54)
   at at.sozvers.hvb.pkt.util.PktVersicherungsverlauf.<init>(PktVersicherungsverlauf.java:46)
   at at.sozvers.hvb.pkt.util.PensionskontoBuilder.buildPensionskonten(PensionskontoBuilder.java:114)
   at at.sozvers.hvb.pkt.model.versicherter.VersicherterBE.buildPensionskonten(VersicherterBE.java:742)
   at at.sozvers.hvb.pkt.model.versicherter.VersicherterBE.update(VersicherterBE.java:532)
   at at.sozvers.hvb.pkt.service.impl.PensionskontoServiceImpl.loadOrCreateVersicherter(PensionskontoServiceImpl.java:513)
   at at.sozvers.hvb.pkt.service.impl.PensionskontoServiceImpl.beauskunfte(PensionskontoServiceImpl.java:487)


Name and version of the database you are using:
Oracle 9.2i

The generated SQL (show_sql=true):
None

Debug level Hibernate log excerpt:


In general my domain model looks as follows: I have a Class Versicherter with a persistent set of Versicherungsverhaeltnisse, which in turn hav a persistent set of Beitragsgrundlagen. All associations are maped bidirectional, all sets have a cascade of all-delete-orphan

My problem: If I insert a new Versicherungsverhaeltnis into Versicherter (and this Versicherungsverhaeltnis has new Beitragsgrundlagen) everything works as expected. However, if I use an already existing Versicherungsverhaeltnis and add a new Beitragsgrundlage, I get the above exception, when the session is implicitly flushed, when the next query is performed. However, if I explicitly flush the session, with session.flush() everything works fine again. Why do I have to flush the session? Any ideas?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 24, 2006 7:51 am 
Regular
Regular

Joined: Tue May 16, 2006 3:32 am
Posts: 117
When you add a new Beitragsgrundlagen, do you set both its (many-to-one) vvh and versicherter correctly?

Also, what happens if you enable cascade=save-update on both the <many-to-one> s of Beitragsgrundlagen in the hbm?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 27, 2006 4:35 am 
Newbie

Joined: Thu Sep 08, 2005 3:45 am
Posts: 4
Yep, back references are set correctly.

Why would I have to enable the cascading in the reverse direction as well? As far as I understood the cascading I have a persistent Versicherter where the persistent collections are cascaded. Shouldn´t that be enough?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 27, 2006 4:50 am 
Regular
Regular

Joined: Tue May 16, 2006 3:32 am
Posts: 117
Yes, normally that should be enough. However, it seems that it is trying to save a BeitragsgrundlageBE which has an unsaved VersicherungsverhaeltnisBE. You could check if this is so, by setting the cascade as save-update. This is just for debugging.


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.