Hibernate version:3
Hello all,
I need to have a one-to-many relation between 2 tables.
the "parent" table is:
Code:
<class
name="com.eaf.model.TemparioPartiDanno"
table="atm_tempario_parti_danno"
select-before-update="false"
dynamic-update="true"
dynamic-insert="true"
optimistic-lock="all"
>
<id
name="codTParteDanno"
column="cod_t_parte_danno"
type="java.lang.String"
length="3"
unsaved-value="undefined"
>
<generator class="assigned">
</generator>
....
</class>
</hibernate-mapping>
the "child":
Code:
<hibernate-mapping>
<class
name="com.eaf.model.AtmFattDettaglioCommesse"
table="atm_fatt_dettaglio_commesse"
select-before-update="false"
dynamic-update="false"
dynamic-insert="false"
optimistic-lock="version"
>
<id
name="idFattDettaglioCommesse"
column="id_fatt_dettaglio_commesse"
type="java.lang.Integer"
>
<generator class="increment">
</generator>
</id>
....
</many-to-one>
<!-- imported bi-directional many-to-one association to TemparioPartiDanno -->
<many-to-one
name="TemparioPartiDanno"
class="com.eaf.model.TemparioPartiDanno"
not-null="false"
outer-join="auto"
>
<column name="cod_t_parte_danno" />
</many-to-one>
</class>
</hibernate-mapping>
The problem occours when I set a NULL foreing key "cod_t_parte_danno"
I do have this Exception:
Code:
[eaf] DEBUG [http-8080-Processor24] AtmFattDettaglioCommesseDAOHibernate.saveAtmFattDettaglioCommesse(75) | atmFattDettaglioCommesse's id: 9
[eaf] ERROR [http-8080-Processor24] AbstractFlushingEventListener.performExecutions(277) | Could not synchronize database state with session
org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing: com.eaf.model.TemparioPartiDanno
at org.hibernate.engine.ForeignKeys.getEntityIdentifierIfNotUnsaved(ForeignKeys.java:216)
at org.hibernate.type.EntityType.getIdentifier(EntityType.java:99)
at org.hibernate.type.ManyToOneType.nullSafeSet(ManyToOneType.java:63)
at org.hibernate.persister.entity.BasicEntityPersister.dehydrate(BasicEntityPersister.java:1617)
at org.hibernate.persister.entity.BasicEntityPersister.update(BasicEntityPersister.java:1963)
at org.hibernate.persister.entity.BasicEntityPersister.updateOrInsert(BasicEntityPersister.java:1909)
at org.hibernate.persister.entity.BasicEntityPersister.update(BasicEntityPersister.java:2149)
at org.hibernate.action.EntityUpdateAction.execute(EntityUpdateAction.java:75)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:239)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:223)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:137)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:274)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
Please help me! I tried ANYTHING, read ANY DOCUMENTATION, I really cannot figure out how to fix it!
please, please, please!
MANY thanks in advance for the answer
Francesco Ronchi