-->
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: Three classes, one <set/> for each one= "not-null
PostPosted: Fri Sep 16, 2005 2:08 pm 
Newbie

Joined: Wed May 04, 2005 1:53 pm
Posts: 3
When I use two classes Asiento and DetalleAsiento and then insert DetalleAsiento in my set of Asiento.. and save this... it is work... But when I use three classes Asiento, DetalleAsiento and DistribucionDetalleAsiento and then insert DistribucionDetalleAsiento in my set of DetalleAsiento and then DetalleAsiento in my set of Asiento.. it is not work why????? Please help me!!!

Hibernate version: 3

Mapping documents:
Class Asiento:
<hibernate-mapping>
<class name="tandi.contabilidad.Asiento" table="ASIENTO" >

<id name="id" column="ID" >
<generator class="tandi.dao.GeneradorSecuenciaHibernate"/>
</id>
.......
<set name="detalleAsientos" lazy="true" inverse="false" cascade="all" >
<key>
<column name="ASIENTOID"/>
</key>
<one-to-many class="tandi.contabilidad.DetalleAsiento" />
</set>
</class>
</hibernate-mapping>

Class DetalleAsiento:
<hibernate-mapping>
<class name="tandi.contabilidad.DetalleAsiento" table="DETALLEASIENTO" >

<id name="id" column="ID" >
<generator class="tandi.dao.GeneradorSecuenciaHibernate"/>
</id>
.......
<many-to-one name="asiento" class="tandi.contabilidad.Asiento" not-null="true">
<column name="ASIENTOID" />
</many-to-one>
<set name="distribucionesDetalleAsiento" lazy="true" inverse="false" cascade="all">
<key>
<column name="DETALLEASIENTOID"/>
</key>
<one-to-many class="tandi.contabilidad.DistribucionDetalleAsiento"/>
</set>
</class>
</hibernate-mapping>

Class DistribucionDetalleAsiento:
<hibernate-mapping>
<class name="tandi.contabilidad.DistribucionDetalleAsiento" table="distribucionDetalleAsiento" >

<id name="id" column="ID" >
<generator class="tandi.dao.GeneradorSecuenciaHibernate"/>
</id>
.......
<many-to-one name="detalleAsiento" class="tandi.contabilidad.DetalleAsiento" not-null="true">
<column name="detalleAsientoId" />
</many-to-one>
</class>
</hibernate-mapping>


Code between sessionFactory.openSession() and session.close():
Asiento asiento = new Asiento();
asiento.setNombre("miAsiento");
DetalleAsiento detalleAsiento = new DetalleAsiento();
detalleasiento.setNombre("miDetalleAsiento");
DistribucionDetalleAsiento distribucionDetalleAsiento = new DistribucionDetalleAsiento();
distribucionDetalleAsiento.setNombre("myDistribucionDetalleAsiento ");
detalleAsiento.getDistribucionesDetalleAsiento.add(distribucionDetalleAsiento);
asiento.getDetallesAsiento.add(detalleAsiento);
myDao().save(asiento);//This fails!!! why?

Full stack trace of any exception that occurs:
org.springframework.orm.hibernate3.HibernateSystemException: not-null property references a null or transient value: tandi.contabilidad.DistribucionDetalleAsiento.detalleAsiento; nested exception is org.hibernate.PropertyValueException: not-null property references a null or transient value: tandi.contabilidad.DistribucionDetalleAsiento.detalleAsiento
org.hibernate.PropertyValueException: not-null property references a null or transient value: tandi.contabilidad.DistribucionDetalleAsiento.detalleAsiento
at org.hibernate.engine.Nullability.checkNullability(Nullability.java:72)
at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:235)
at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:159)
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:107)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:184)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:173)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.performSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:96)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:69)
at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:464)
at org.hibernate.engine.Cascades$5.cascade(Cascades.java:154)
at org.hibernate.engine.Cascades.cascadeAssociation(Cascades.java:771)
at org.hibernate.engine.Cascades.cascade(Cascades.java:720)
at org.hibernate.engine.Cascades.cascadeCollection(Cascades.java:895)
at org.hibernate.engine.Cascades.cascadeAssociation(Cascades.java:792)
at org.hibernate.engine.Cascades.cascade(Cascades.java:720)
at org.hibernate.engine.Cascades.cascade(Cascades.java:847)
at org.hibernate.event.def.AbstractSaveEventListener.cascadeAfterSave(AbstractSaveEventListener.java:362)
at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:264)
at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:159)
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:107)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:184)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:173)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.performSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:96)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:69)
at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:464)
at org.hibernate.engine.Cascades$5.cascade(Cascades.java:154)
at org.hibernate.engine.Cascades.cascadeAssociation(Cascades.java:771)
at org.hibernate.engine.Cascades.cascade(Cascades.java:720)
at org.hibernate.engine.Cascades.cascadeCollection(Cascades.java:895)
at org.hibernate.engine.Cascades.cascadeAssociation(Cascades.java:792)
at org.hibernate.engine.Cascades.cascade(Cascades.java:720)
at org.hibernate.engine.Cascades.cascade(Cascades.java:847)
at org.hibernate.event.def.AbstractSaveEventListener.cascadeAfterSave(AbstractSaveEventListener.java:362)
at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:264)
at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:159)
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:107)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:184)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:173)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.performSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:96)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:69)
at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:464)
at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:459)
at org.springframework.orm.hibernate3.HibernateTemplate$18.doInHibernate(HibernateTemplate.java:612)
at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:310)
at org.springframework.orm.hibernate3.HibernateTemplate.saveOrUpdate(HibernateTemplate.java:609)
at plenix.components.dao.DaoHibernate.store(DaoHibernate.java:20)
at tandi.contabilidad.GestorContabilizacionImpl.almacenarAsiento(GestorContabilizacionImpl.java:610)
at tandi.contabilidad.GestorContabilizacionImpl.anular(GestorContabilizacionImpl.java:1149)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:310)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:163)
at $Proxy5.anular(Unknown Source)
at tandi.test.contabilidad.contabilizacion.MayorizacionTest.testContabilizarFacturaDiferida(MayorizacionTest.java:73)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at com.intellij.rt.execution.junit2.JUnitStarter.main(JUnitStarter.java:31)

Name and version of the database you are using:
oracle 9i

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 16, 2005 2:24 pm 
Newbie

Joined: Tue May 11, 2004 10:47 am
Posts: 16
You need to add

distribucionDetalleAsiento.setDetalleAsiento(detalleAsiento)

before calling save.

Also, in the DistribucionDetalleAsiento mapping file, I believe you want to set inverse="true" in the many-to-one:

<many-to-one name="detalleAsiento" class="tandi.contabilidad.DetalleAsiento" not-null="true" inverse="true">

If this helps, please credit...


Luke


Top
 Profile  
 
 Post subject: I did it and it's work but.....
PostPosted: Fri Sep 16, 2005 3:41 pm 
Newbie

Joined: Wed May 04, 2005 1:53 pm
Posts: 3
Thanks for you help.... I get your idea but I don understand the reason.. First I never write detalleAsiento.setAsiento(asiento) nevertheless when I have two classes this work... so why this don't work when I have three classes... why I must write distribucionDetalleAsiento.setDetalleAsiento(detalleAsiento) for getting it works?. Second I can't understand the core of "inverse" property..

Thanks for all....


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 16, 2005 3:54 pm 
Newbie

Joined: Tue May 11, 2004 10:47 am
Posts: 16
Ok, let me try this again. First of all, I was mistaken when I said add "inverse=true" to the many-to-one - I should have said to put "inverse=true" on the one-to-many.

I _think_ you use use inverse whenever you have a bidirectional association, as you do here. Then the relationship is only saved to the database when processing the non-inverse side of the relationship.

Still, this doesn't answer your original question. So, I would suggest setting inverse=true on both one-to-many's, and calling both

detalleAsiento.setAsiento(asiento)
and
distribucionDetalleAsiento.setDetalleAsiento(detalleAsiento)

I'm not sure why you observed it cascading the first relationship but not the second. Let me know if this works....


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.