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?