-->
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.  [ 5 posts ] 
Author Message
 Post subject: A purist question (session.createQuery or session.find)?
PostPosted: Tue Jan 27, 2004 7:50 am 
Pro
Pro

Joined: Wed Oct 08, 2003 10:31 am
Posts: 247
Being a purist in terms of performance, sql generated code, etc., which method is the better:

Method 1
Code:
Query query = session.createQuery("from pt.Xpto as x where x.ref like upper(:ref)");
query.setParameter("ref", "%" + vref + "%");
List res = query.list();


Method 2
Code:
List res = session.find("from pt.Xpto as x where x.ref like upper(?)", ref, Hibernate.STRING);


They look the same...

Thanks in advance.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 27, 2004 7:52 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
One is using named parameters and the other positional parameters. They evaluate to the same SQL, of course. The difference in usage should be clear if you look at it.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 27, 2004 7:58 am 
Pro
Pro

Joined: Wed Oct 08, 2003 10:31 am
Posts: 247
christian wrote:
One is using named parameters and the other positional parameters. They evaluate to the same SQL, of course. The difference in usage should be clear if you look at it.


Sorry... I think I didn't explain my point correctly.
Visualy they don't look the same, of course. I ment in terms of functionality and generated code.

In terms of performance, are they the same?

PS: thanks for the quick reply christian (as usual).


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 27, 2004 8:00 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
They are the same.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 27, 2004 8:03 am 
Pro
Pro

Joined: Wed Oct 08, 2003 10:31 am
Posts: 247
christian wrote:
They are the same.


Thanks.


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