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.  [ 3 posts ] 
Author Message
 Post subject: one-to-many mapping - too many results
PostPosted: Fri Sep 14, 2007 10:56 am 
Newbie

Joined: Tue Aug 28, 2007 2:22 pm
Posts: 7
Hola! Necesito algo de ayuda.

Tengo un modelo parent-child típico (Operaciones tienen muchos Procedimientos).
Realizo una consulta de Operaciones, pero obtengo una Operación por cada Procedimiento.
Es decir, si tengo 14 Operaciones y 45 Procedimientos, obtengo 45 objetos Operacion:

Operacion 1 contiene 2 Procedimientos;
Operacion 1 contiene 2 Procedimientos;
Operacion 2 contiene contiene 4 Procedimientos;
Operacion 2 contiene contiene 4 Procedimientos;
Operacion 2 contiene contiene 4 Procedimientos;
Operacion 2 contiene contiene 4 Procedimientos;
Operacion 3...;

Cada Operacion contiene una lista de Procedimientos bien mapeada. No entiendo por qué se repiten los objetos. A continuación, muestro la info importante:

Code between sessionFactory.openSession() and session.close():
ICriteria icOperaciones = isession.CreateCriteria(typeof(Operacion));
IList<Operacion> j = icOperaciones.List<Operacion>();

Hibernate version: 1.2

Mapping documents:
Code:
Operacion.hbm.xml

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping...>
<class name="Operacion" table="[desarrollo].[dbo].[OperCapac_Operaciones]">
<id name="Id_Operacion" column="id_operacion" type="int"><generator class="assigned"/></id>
<bag name="ListaProcedimientos" table="OperCapac_Procedimientos" inverse="true" fetch="join" cascade="all">
<key column="id_operacion"/>
<one-to-many class="Procedimiento"/>
</bag>

</class>
</hibernate-mapping>

Code:
Procedimiento.hbm.xml

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping ...>
<class name="Procedimiento" table="[desarrollo].[dbo].[OperCapac_Procedimientos]">
<!-- Propiedades -->
<id name="Id_procedimiento" column="id_procedimiento" type="int"><generator class="assigned"/></id>
<many-to-one name="Operacion" column="id_operacion" not-null="true" cascade="all-delete-orphan"/>
</class>
</hibernate-mapping>

Name and version of the database you are using:
SQL Server 2005

Se agradecen todas las sugerencias.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 14, 2007 3:18 pm 
Newbie

Joined: Tue Aug 28, 2007 2:22 pm
Posts: 7
La respuesta estaba en la página 188 (!).

criteria.SetResultTransformer(CriteriaUtil.DistinctRootEntity);

ref.: http://forum.hibernate.org/viewtopic.php?t=952693

¿hay una mejor manera de resolverlo?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 14, 2007 4:22 pm 
Regular
Regular

Joined: Fri Jan 20, 2006 7:45 pm
Posts: 97
Location: San Antonio, TX
No se ahora, necisito a pensar sobre tu problema. Pero en primer lugar, no creo que qieres a usa cascade="all" en la mapa for su lista de Procedimientos. Con esto, si usted deletes un Procedimiento con el session, va a delete el Operacion que contiene eso Procedimiento. Y consecuentemente va a delete todos los otros Procedimiento bajo del Operacion.

Para la problema central, pienso que si usa usted fetch="join" en el declaracion para el bag usted tendra problemas como estas. Creo que en esto situacion, fetch="join" causas un outer join entre los Operacions y los Procedimientos. Se diga que Operacion 1 contiene 2 Procedimientos, y si tiene Operacion 2 contiene 4 Procedimientos. Si tiene un outer join debido al bag, usted tiendra listas como estas.

Esto es mi teoria sobre su problema. Usted intenta poner fetch="join" en one-to-many y intenta su prueba otra ves, okay?

_________________
Dum spiro, spero
-------------------------------
Rate my post if it helps...


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