-->
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: Tables mapping in SQL select query
PostPosted: Fri Jul 10, 2009 5:25 am 
Beginner
Beginner

Joined: Thu Sep 18, 2008 5:18 am
Posts: 28
Hi, does one have to map all tables appearing in a query ... Consider the following SQL query ...
Code:
SELECT m.force, m.surname, m.init, a.id,
   NVL(a.qualification_name_not_found, b.qualification_name) qual_name,
   q.qualcode, m.app_cde,
   r.description AS rank
FROM locnavy.MEMBERS m,
   nlrd.QUALIFICATION_ENROLMENT a,
   nlrd.MASTER_QUALIFICATION b,
   JOB_QUAL_LNK c,
   RANKS r,
   JOB_QUALIFICATION q
WHERE a.id = m.force
   AND r.rank_id = m.rank_cde
   AND a.qualification_id = b.qualification_id (+)
   AND a.qualification_id = c.qualification_id
   AND a.learner_achievement_status_id IN (2,32)
   AND c.job_qualification_id = q.job_qualification_id"
   AND q.qualcode != 'XXX'
   AND (m.mustering_cde = '" + mustCode + "' OR '"+ mustCode +"' IS NULL)
   AND (m.rank_cde = '" + rankCode+ "' OR '" + rankCode+ "' IS NULL)
   AND NVL(m.STATUS,'A') = 'A' AND m.app_cde IN ('MC','MG','MP','PE','PF','PV')

Note that joins are not used as this was written under Oracle 8i ... For the purpose of this query only MEMBERS object/POJO is used to contain the results, other tables appearing here i used to help retrieve the results.
Code:
QUALIFICATION_ENROLMENT
MASTER_QUALIFICATION
JOB_QUAL_LNK
RANKS
JOB_QUALIFICATION

In hibernate SQL/HQL query, would i need to have each table appearing here mapped? Is there a rule that all table joins must be mapped and appearing in hibernate.cfg.xml?


Top
 Profile  
 
 Post subject: Re: Tables mapping in SQL select query
PostPosted: Fri Jul 10, 2009 5:57 am 
Newbie

Joined: Wed Jul 01, 2009 10:56 am
Posts: 7
there is no need to do so, i mean, you can make ONLY a POJO which contains all those parameters (they work for the select that you wrote, if they give problems with other things, i dont know, since im starting w hibernate).


for example:


Code:
<class
      name="pruebahibernate_1.AparatoYConf"
      table="TIPOS_APARATO">
        <id
         name="idtaparato"
         column="id_t_aparato">
        </id>
      <property
         name="descripcion"
         column="DESCRIPCION"/>
        <join table="TIPOS_APARATO_CONF">
            <key column="id_t_aparato"/>
            <property name="fdesdetap" column="f_desde_tap"/>
            <property name="fhastatap" column="f_hasta_tap"/>
            <property name="codcne" column="cod_cne"/>
        </join>
    </class>


would fit (i think that you dont need to join in the mapping, just add more properties, but this mapping was designed to work with HQL =))

Code:
SELECT A.id_t_aparato, descripcion, f_desde_tap, f_hasta_tap, cod_cne
        FROM TIPOS_APARATO A, TIPOS_APARATO_CONF B
        WHERE A.id_t_aparato=B.id_t_aparato


Top
 Profile  
 
 Post subject: Re: Tables mapping in SQL select query
PostPosted: Fri Jul 10, 2009 7:53 am 
Beginner
Beginner

Joined: Thu Sep 18, 2008 5:18 am
Posts: 28
Black_ice wrote:
there is no need to do so, i mean, you can make ONLY a POJO which contains all those parameters (they work for the select that you wrote, if they give problems with other things, i dont know, since im starting w hibernate).


for example:


Code:
<class
      name="pruebahibernate_1.AparatoYConf"
      table="TIPOS_APARATO">
        <id
         name="idtaparato"
         column="id_t_aparato">
        </id>
      <property
         name="descripcion"
         column="DESCRIPCION"/>
        <join table="TIPOS_APARATO_CONF">
            <key column="id_t_aparato"/>
            <property name="fdesdetap" column="f_desde_tap"/>
            <property name="fhastatap" column="f_hasta_tap"/>
            <property name="codcne" column="cod_cne"/>
        </join>
    </class>


would fit (i think that you dont need to join in the mapping, just add more properties, but this mapping was designed to work with HQL =))

Code:
SELECT A.id_t_aparato, descripcion, f_desde_tap, f_hasta_tap, cod_cne
        FROM TIPOS_APARATO A, TIPOS_APARATO_CONF B
        WHERE A.id_t_aparato=B.id_t_aparato


isn't join table used in hibernate inheritance mapping, within a <subclass> tag ...?


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.