-->
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.  [ 7 posts ] 
Author Message
 Post subject: Problems with org.hibernate.TransientObjectException
PostPosted: Mon Jul 03, 2006 11:34 am 
Newbie

Joined: Mon May 29, 2006 6:07 am
Posts: 12
Hi I am using Hibernate 3.0 i i have got this code:
Code:
anu.setEmpleado(empl);
depto.addAnuncio(anu);
session.beginTransaction();
session.update(depto);
session.getTransaction().commit();
session.close();


the exception:

Code:
  org.hibernate.TransientObjectException: model.Empleado
org.hibernate.TransientObjectException: model.Empleado
   at org.hibernate.engine.ForeignKeys.getEntityIdentifierIfNotUnsaved(ForeignKeys.java:216)
   at org.hibernate.type.EntityType.getIdentifier(EntityType.java:108)
   at org.hibernate.type.ManyToOneType.nullSafeSet(ManyToOneType.java:71)
   at org.hibernate.persister.entity.AbstractEntityPersister.dehydrate(AbstractEntityPersister.java:1826)
   at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2172)
   at org.hibernate.persister.entity.AbstractEntityPersister.updateOrInsert(AbstractEntityPersister.java:2118)
   at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2374)
   at org.hibernate.action.EntityUpdateAction.execute(EntityUpdateAction.java:91)
   at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:248)
   at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:232)
   at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:140)


the mappings are:


Code:
<class name="model.calidad.Aviso" table="Aviso">
        <id name="aviso_id" column="aviso_id">
            <generator class="increment"/>
        </id>
     
        <property name="nombre" type="string"/>
        <property name="descripcion" type="string"/>
        <property name="fecha" type="java.util.Date"/>
        <property name="envioEmail" type="boolean"/>
        <many-to-one name="empleado" column="empleado_id" lazy="false" cascade="persist" class="model.Empleado"></many-to-one>
       
        <set lazy="false" cascade="all" name="comentarios">
           <key column="aviso_id"/>
           <one-to-many class="model.calidad.Comentario"/>
        </set>


Code:


    <class name="model.Departamento" table="Departamento" >
        <id name="departamento_id" column="departamento_id">
            <generator class="increment"/>
        </id>
       
        <property name="descripcion" type="string"/>
        <property name="nombre" type="string"/>
       
        <set name="puestos" cascade="all" lazy="false" >
           <key not-null="true" column="departamento_id"/>
         <one-to-many class="model.Puesto"/>
        </set>
        <set name="anuncios" cascade="all" lazy="false" >
           <key not-null="true" column="departamento_id"/>
         <one-to-many class="model.calidad.Anuncio"/>
        </set>
    </class>


It has Anyone an idea? thanks a lot


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 03, 2006 2:16 pm 
Regular
Regular

Joined: Wed Jan 11, 2006 12:49 pm
Posts: 64
Location: Campinas, Brazil
Object "empl" (setEmpleado) is probably missing the ID property (meaning the property is null). At least that happened every time I get that exception.

_________________
Henrique Sousa
Don't forget to rate useful responses


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 04, 2006 3:55 am 
Newbie

Joined: Mon May 29, 2006 6:07 am
Posts: 12
Thanks for yor reply but this is not the problem, the Id is not a null value, but here is a new detail of the problem:
Code:
Could not synchronize database state with session
org.hibernate.TransientObjectException: model.Empleado
   at org.hibernate.engine.ForeignKeys.getEntityIdentifierIfNotUnsaved(ForeignKeys.java:216)
   at org.hibernate.type.EntityType.getIdentifier(EntityType.java:108)
   at org.hibernate.type.ManyToOneType.nullSafeSet(ManyToOneType.java:71)
   at org.hibernate.persister.entity.AbstractEntityPersister.dehydrate(AbstractEntityPersister.java:1826)
   at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2172)
   at org.hibernate.persister.entity.AbstractEntityPersister.updateOrInsert(AbstractEntityPersister.java:2118)
   at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2374)


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 04, 2006 9:57 am 
Expert
Expert

Joined: Tue Dec 28, 2004 7:02 am
Posts: 573
Location: Toulouse, France
I think that hlfsousa was pointing the right direction. Your objects have ids that are "user-assigned" : you didn't specify the id generation strategy, so you have to manage it by yourself.

Did you set the id of your depto object, and every objects ? Is empleado also an entity ? Did you call setId() on every entities before trying to save it ?

Moreover, why are you calling update(), do you know why you're doing it ? Most of the times, you should prefer to simply call save(), as said in the reference doc :
http://www.hibernate.org/hib_docs/v3/re ... veorupdate
Quote:
Firstly, so long as you are not trying to use instances from one session in another new session, you should not need to use update(), saveOrUpdate(), or merge(). Some whole applications will never use either of these methods.

_________________
Baptiste
PS : please don't forget to give credits below if you found this answer useful :)


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 04, 2006 11:01 am 
Newbie

Joined: Mon May 29, 2006 6:07 am
Posts: 12
Thanks for your reply but, that´s not the problem, it is the same problem for Save() or Update(). An answering your question, yes i´m sure that neither ID is null. Any other idea?

Thanks a lot everyone


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 04, 2006 11:09 am 
Expert
Expert

Joined: Tue Dec 28, 2004 7:02 am
Posts: 573
Location: Toulouse, France
The error "could not synchronize state..." also appears when the id is one that's already used in the database (primary key constraint violation, in this case).

Are you also sure your id are not already used ?

_________________
Baptiste
PS : please don't forget to give credits below if you found this answer useful :)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 05, 2006 4:01 am 
Newbie

Joined: Mon May 29, 2006 6:07 am
Posts: 12
Thanks a lot for your reply, It was the problem


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 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.