-->
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.  [ 6 posts ] 
Author Message
 Post subject: Dynamic Query : what is best fetch HQL or Criteria ?
PostPosted: Fri Sep 30, 2005 6:35 am 
Newbie

Joined: Wed Aug 10, 2005 8:07 am
Posts: 14
Hibernate version:3.0.5

Hi,
i desire to generate a dynamic query which depends of some parameters
Something like that :
Code:

StringBuffer sb = new StringBuffer("Select toto ");
for(int i = 0;i<tabDate.length;i++)
{
   sb.append(" b"+i+",");
}
Query q = new Query(sb.toString());
....      



This kind of code works well , but it is not so usefull (comma, ....) and difficult for maintenance !

So, is there others solutions to create a query like that , for example with Criteria.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 03, 2005 8:38 am 
Newbie

Joined: Thu Sep 01, 2005 12:39 pm
Posts: 16
Location: porto alegre, brazil
if your query is build in a dinamic way, it's best ( and easier ) to use Criteria.

_________________
Bsc. Tiago Martins
software engineer

Please don't forget to give credit if/when you get helpful information.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 03, 2005 10:23 am 
Newbie

Joined: Wed Aug 10, 2005 8:07 am
Posts: 14
Ok thanks, but is it possible to retrieve multiple differents Object (eg : Account, Bank, User, ....) from a Criteria query ?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 03, 2005 10:41 am 
Newbie

Joined: Thu Sep 01, 2005 12:39 pm
Posts: 16
Location: porto alegre, brazil
yes - but I'm not certain how - I think it's usin createAlias or setFetchMode methods.

http://www.hibernate.org/hib_docs/v3/re ... teria.html this may help, though it dont tell how are the generated sql or other *really* usefull stuff.

_________________
Bsc. Tiago Martins
software engineer

Please don't forget to give credit if/when you get helpful information.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 03, 2005 11:13 am 
Newbie

Joined: Wed Aug 10, 2005 8:07 am
Posts: 14
Thanks, i will try with fetchMode , but i don't understand that well.
Sometimes the HQL method is more usefull but error-prone ....


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 03, 2005 2:15 pm 
Expert
Expert

Joined: Sat Jun 12, 2004 4:49 pm
Posts: 915
Quote:
if your query is build in a dinamic way, it's best ( and easier ) to use Criteria.


hql is better and Criteria is easier

Criteria add any hql and you can't control it and so , hql is better

Criteria is easier if you can do what you want do


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