-->
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.  [ 2 posts ] 
Author Message
 Post subject: Guessing Query Parameter Types
PostPosted: Sat Mar 04, 2006 7:42 pm 
Newbie

Joined: Sat Mar 04, 2006 7:27 pm
Posts: 1
Location: Phoenix, AZ
Hibernate version: 3.1.2 w/ Annotations

Name and version of the database you are using: MySQL 4.1

I am looking for a way to reliably guess type information for named parameters in HQL queries. My queries are generally in @NamedQuery annotations if it matters.

I did a little digging in the source code and some pieces look promising (Namely the HQLQueryPlan.getParameterMetaData()). It looks like most of this API is under the hood, exposed via SessionFactoryImplementor but not via the SessionFactory interface I'm accustomed to using.

Is there a "public api" sort of way to get at this information? Would it be reasonable to cast my SessionFactory to a SessionFactoryImpl so I can access the query plan cache?

Specifically, suppose I have a named HQL query:

Code:
from Product where partNumber = :partNumber


At runtime, I'd like to determine the best java type for the "partNumber" parameter in my query. My ultimate goal is to generate typesafe wrappers for my queries at build time using a custom ant task.

I suspect there are cases where the type can't be reliably determined. If there are any considerations along these lines I'd love to hear them as well.

I know this is an abnormal use of Hibernate, but if anyone has any guidance before I start writing code it would certainly save me a lot of wrong directions before I figure it out. Thanks so much!

Geoff


Top
 Profile  
 
 Post subject: Re: Guessing Query Parameter Types
PostPosted: Wed Aug 05, 2009 2:42 am 
Newbie

Joined: Tue Dec 09, 2008 6:55 am
Posts: 12
Hi,

I'm trying to achieve exactly the same thing. I used HQLQueryPlan and it works fine for most of the cases.

One problem I have is on using a query like "select client from Client where client.seq in (:clientseq)"
Here, I cant seem to figure out through any api that setParameterList will need to be called for the named parameter. It just returns the data type of the attribute.

Is there any way to figure out that a particular parameter expects a list?

Any ideas?

Thanks.

Regards
Kaizer


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