-->
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: Which method is better or quicker?
PostPosted: Mon Apr 05, 2004 5:36 am 
Pro
Pro

Joined: Wed Oct 08, 2003 10:31 am
Posts: 247
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 1
Code:
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 2
Code:
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.


Top
 Profile  
 
 Post subject: Re: Which method is better or quicker?
PostPosted: Mon Apr 05, 2004 12:45 pm 
Pro
Pro

Joined: Wed Oct 08, 2003 10:31 am
Posts: 247
Any ideas please?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 05, 2004 2:58 pm 
Senior
Senior

Joined: Wed Mar 24, 2004 11:40 am
Posts: 146
Location: Indianapolis, IN, USA
why don't you turn explain on your database and execute both queries? it should tell you which one is more efficient.

I prefer using Criteria based search as much as possible and resort to HQL only when the query is really complicated.


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.