-->
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.  [ 1 post ] 
Author Message
 Post subject: 3-table query trouble, help!
PostPosted: Thu Mar 02, 2006 10:26 pm 
Newbie

Joined: Thu Mar 02, 2006 10:09 pm
Posts: 1
please! , some one have a running example? I have tried all the sample codes in every book but nothing works. I think maybe the mapping is wrong but I just don't know what is the problem.

I just have to make a query using 3 tables, and I want to return data from the 3 tables, how do I do that?


Hibernate-Version: 3.0.5

<hibernate-mapping>

<class name="Model.BusinessObject.CatServicio" table="CAT_SERVICIOS" lazy="false">

<id name="servicioId" type="java.lang.Long" column="SERVICIO_ID">
<generator class="sequence">
<param name="sequence"></param>
</generator>
</id>

<property name="nombre" type="java.lang.String" column="NOMBRE" not-null="true" length="50"/>
<property name="costo" type="java.lang.Double" column="COSTO" not-null="true" length="126"/>

<!-- Associations -->

<!-- bi-directional one-to-many association to ServiciosArea -->

<set name="serviciosAreas" lazy="true" inverse="true" cascade="all">
<key>
<column name="SERVICIO_ID" />
</key>
<one-to-many class="Model.BusinessObject.ServiciosArea"/>
</set>

<!-- bi-directional one-to-many association to OrdenServicio -->

<set name="ordenServicios" lazy="true" inverse="true" cascade="all" >
<key>
<column name="SERVICIO_ID" />
</key>
<one-to-many class="Model.BusinessObject.OrdenServicio" />
</set>

</class>

<sql-query name="servicesByUnit">
<return alias="servicio" class="Model.BusinessObject.CatServicio"/>
SELECT servicio.* FROM CAT_SERVICIOS servicio, SERVICIOS_AREAS rel, UNIDAD unid
WHERE unid.UNIDAD_ID = rel.UNIDAD_ID
AND rel.SERVICIO_ID = servicio.SERVICIO_ID AND unid.UNIDAD_ID = :unidad
</sql-query>

<sql-query name="servicesByWordsUnit">
<return alias="servicio" class="Model.BusinessObject.CatServicio"/>
<!-- <return alias="rel" class="Model.BusinessObject.ServiciosArea"/>
<return alias="unid" class="Model.BusinessObject.Unidad"/> -->
SELECT servicio.*
FROM CAT_SERVICIOS servicio, SERVICIOS_AREAS rel, UNIDAD unid
WHERE rel.SERVICIO_ID = servicio.SERVICIO_ID AND unid.UNIDAD_ID = rel.UNIDAD_ID
AND (unid.UNIDAD_ID = :uni OR servicio.NOMBRE LIKE :namePattern )
</sql-query>

<sql-query name="allServices">
<return alias="ser" class="Model.BusinessObject.ListaServicio"/>
<return alias="ser" class="Model.BusinessObject.CatServicio"/>
<return alias="hor" class="Model.BusinessObject.ServicioHorario"/>
<return alias="ind" class="Model.BusinessObject.CatIndicacione"/>
SELECT ser.SERVICIO_ID, ser.COSTO, ser.NOMBRE, hor.HORARIO, ind.DESCRIPCION
FROM CAT_SERVICIOS ser, SERVICIO_HORARIO hor, SERVICIO_INDICACION catin, CAT_INDICACIONES ind
WHERE ser.SERVICIO_ID = hor.SERVICIO_ID AND ser.SERVICIO_ID = catin.SERVICIO_ID
AND catin.INDICACION_ID = ind.INDICACION_ID
</sql-query>

</hibernate-mapping>




[b]


ORACLE 9



Debug level Hibernate log excerpt:


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.