-->
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.  [ 1 post ] 
Author Message
 Post subject: column name as parameter in namedQuery annotation?
PostPosted: Thu Oct 18, 2007 10:09 am 
Newbie

Joined: Thu Oct 18, 2007 9:48 am
Posts: 1
Location: New York
I have around 40 fields that are requested as individual set of data based on a date range. I am trying to pass the column name for the field as a parameter to the named query and it does not seem to be working. How can I do that? Is it even possible?



@NamedNativeQuery(name = "fbs.fieldValue", query = "select ft1.rep_date as date, :fieldName as value from asset a, fundamental_t1 ft1, fundamental_bs fbs " +
"where a.asset_key = :assetKey and ft1.asset_id = a.id and fbs.fundamental_id = ft1.id and rep_date is not null and " +
"rep_date >= :startDate and rep_date <= :endDate order by rep_date", resultSetMapping = "fbs.fieldValue")

Code between sessionFactory.openSession() and session.close():

Query q = getSession().getNamedQuery(getFielValueQueryName());

q.setString("assetKey", assetKey);
q.setString("fieldName", fieldName);
q.setDate("startDate", startDate);
q.setDate("endDate", endDate);

Full stack trace of any exception that occurs:

Name and version of the database you are using: Mysql

The generated SQL (show_sql=true):
select ft1.rep_date as date, ? as value from asset a, fundamental_t1 ft1, fundamental_bs fbs where a.asset_key = ? and ft1.asset_id = a.id and fbs.fundamental_id = ft1.id and rep_date is not null and rep_date >= ? and rep_date <= ? order by rep_date

No error occurs but the result returned are in the format:
<date>, assets_total

Basically the field name shows up as the result instead of the field value.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.