Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version: 3.0.5
Mapping documents:
CATEGORY:
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>
ITEM:
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>
Code between sessionFactory.openSession() and session.close():I am using Appfuse with Spring to manage hibernate sessions
Full stack trace of any exception that occurs: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) ...
Name and version of the database you are using:
Postgres 8.0
The generated SQL (show_sql=true):
n/a
Debug level Hibernate log excerpt:
n/a
The question, in short is:
I have CATEGORY table , with an assigned generator.
I have a ITEM table, that may have a CATEGORY, but may also have NO categorization, thus requiring a NULL foreing key to category.
Maybe I'm doing something wrong, but I cannot get hibernate accept a null foreing key on this relation since I always get the above exception.
Is there a way to avoid this?
Thanks in advance.
Francesco Ronchi