I'm using Hibernate 2.1.2.
Here's a simple example mapping file:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >
<hibernate-mapping>
<class
name="vo.MpMpo"
table="mp_mpo"
>
<composite-id name="comp_id" class="vo.MpMpoPK">
<!-- bi-directional many-to-one association to ManPrev -->
<key-many-to-one
name="manPrev"
class="vo.ManPrev"
>
<column name="man_prev_fk" />
</key-many-to-one>
<!-- bi-directional many-to-one association to ManPrevOper -->
<key-many-to-one
name="manPrevOper"
class="vo.ManPrevOper"
>
<column name="man_prev_oper_fk" />
</key-many-to-one>
</composite-id>
<property
name="estado"
type="java.lang.String"
column="estado"
length="1"
/>
</class>
</hibernate-mapping>
I would like to know which method is the better or the quicker in retrieving data:
Method 1Code:
Query query = session.createQuery("select mm.comp_id.manPrevOper from pt.comseal.arsol.vo.MpMpo mm where mm.comp_id.manPrevOper.referencia like upper(:ref_padrao) and mm.comp_id.manPrev.referencia = upper(:man_prev_ref) order by mm.comp_id.manPrevOper.referencia asc");
query.setParameter("ref_padrao", "%" + ref_padrao + "%");
query.setParameter("man_prev_ref", man_prev_ref);
res = query.list();
Method 2Code:
Query query = session.createQuery("select mpo from pt.comseal.arsol.vo.MpMpo mm join mm.comp_id.manPrev mp join mm.comp_id.manPrevOper mpo where mpo.referencia like upper(:ref_padrao) and mp.referencia = upper(:man_prev_ref) order by mpo.referencia asc");
query.setParameter("ref_padrao", "%" + ref_padrao + "%");
query.setParameter("man_prev_ref", man_prev_ref);
res = query.list();
Thanks in advance.