-->
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.  [ 8 posts ] 
Author Message
 Post subject: queries and compilation
PostPosted: Wed Jan 21, 2004 10:16 am 
Newbie

Joined: Wed Jan 21, 2004 10:09 am
Posts: 13
Hi all,

I've recently started using Hibernate, and have been loving it. It just helps so much!

One problem that I have had with it is the queries - the queries are strings, which don't get compiled. It would be nice to be able to have the queries compiled to have them checked for validaty. In particular, I would like to be able to change an objects attribute name, and have the problem highlight for me.

For example, I might have a query:

"from object as o where o.name = ?"

If the attribute 'name' changes in o, the query, because its a string, won't throw a compile exception, and I won't know that there is a problem until runtime. Is there a way around this?

Thanks for any suggestions,

Mark


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 21, 2004 10:53 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Try query in mapping file, it may check that before real HQL call.
For use using the criteria API

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 21, 2004 8:48 pm 
Newbie

Joined: Wed Jan 21, 2004 10:09 am
Posts: 13
Hi Emmanual,

Thanks for the suggestion, but it makes no mention of this capability in the documentation.

"15.3. Named SQL queries
Named SQL queries may be defined in the mapping document and called in exactly the same way as a named HQL query. "

Any other ideas, from Emmanual or others?

Thanks,

Mark


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 22, 2004 4:24 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
He also said the criteria API - check it out.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 22, 2004 8:30 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
mwaschkowski wrote:
Thanks for the suggestion, but it makes no mention of this capability in the documentation.

Well, I know the documentation does not mention that. That's why I asked you to *try*

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 22, 2004 10:17 am 
Newbie

Joined: Wed Jan 21, 2004 10:09 am
Posts: 13
Thanks for the replies gentlemen.

David, I did check the criteria technique, I should have made mention of it in my last post, sorry. Unfortunately I saw no way in which it would accomplish what I desire because of the way criterias are setup:

ie.
List cats = sess.createCriteria(Cat.class)
.add( Expression.like("name", "Fritz%") )
.add( Expression.between("weight", minWeight, maxWeight) )
.list();

The "name" is still being added as a string, which is the problem :(

Emmanual:
I thought about this a bit further, and it seems to me that putting the query in the mapping file is going in the opposite direction than I was hoping to go. If the query is in the mapping file, it will NEVER be compiled time checked right? Or am I missing something here (which is, of course, very possible)?

Thanks again guys,

Mark


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 22, 2004 10:54 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Hibernate *may* load (compile at runtime) HQL in mapping files in the init process, and thus fail at the very begining. But I've never tested.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 22, 2004 5:52 pm 
Newbie

Joined: Wed Jan 21, 2004 10:09 am
Posts: 13
emmanuel wrote:
Hibernate *may* load (compile at runtime) HQL in mapping files in the init process, and thus fail at the very begining. But I've never tested.


Hi Emmanuel,

Actually, its the failure at runtime that I'm trying to avoid! I'm looking for a solution whereby I catch the errors when I recompile my code, NOT when I run it.

--snip from original post:
For example, I might have a query:

"from object as o where o.name = ?"

If the attribute 'name' changes in o, the query, because its a string, won't throw a compile exception, and I won't know that there is a problem until runtime. Is there a way around this?
--end snip

This problem would remain even if Hibernate does compile HQL at runtime, because we are still talking runtime and not compile time.

Well, thanks for the suggestions/thoughts!

Best regards,

Mark


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