[
http://opensource.atlassian.com/projects/hibernate/browse/HHH-4914?page=c...
]
Steve Ebersole commented on HHH-4914:
-------------------------------------
FYI ->
https://forum.hibernate.org/viewtopic.php?f=1&t=1002593
How about you answer the question I've now asked you twice on the forum thread?
How to pass values to Named Query dynamically in Hibernate
----------------------------------------------------------
Key: HHH-4914
URL:
http://opensource.atlassian.com/projects/hibernate/browse/HHH-4914
Project: Hibernate Core
Issue Type: Bug
Affects Versions: 3.1
Reporter: kalyan buddala
I need to create a dynamic query based on the some condition. I don't want to
hardcode this query in my java class.
So that's the reason i want to get this using Named query in hibernate.
Below is how iam trying to implement.
DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
String today = sdf.format(date);
Query query = session.getNamedQuery("findDateDifference");
query.setString(1, today);
List date_Diff_List = query.list();
<sql-query name="findDateDifference"><![CDATA[
select (? - temp.bv_date) as days from
( select CLO_DTE as bv_date from BRAND ) temp]]>
</sql-query>
I need to pass the value to the '?' which is given in above query.
When I run the above code it gives me error as below.
Can anyone please give me some suggestions how to fix this issue.
Hibernate:
select (? - temp.bv_date) as days from
( select CLO_DTE as bv_date from BRAND ) temp
org.hibernate.exception.SQLGrammarException: could not execute query
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:59)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.loader.Loader.doList(Loader.java:1502)
at org.hibernate.loader.Loader.list(Loader.java:1482)
at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:103)
at org.hibernate.impl.SessionImpl.listCustomQuery(SessionImpl.java:1333)
at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:146)
at com.hibernate.ExceptionTest.getDateDifference(ExceptionTest.java:219)
at com.hibernate.ExceptionTest.main(ExceptionTest.java:43)
Caused by: com.ibm.db2.jcc.a.SqlException: DB2 SQL error: SQLCODE: -171, SQLSTATE: 42815,
SQLERRMC: 2;-
at com.ibm.db2.jcc.a.hd.e(hd.java:1659)
at com.ibm.db2.jcc.a.hd.a(hd.java:1235)
at com.ibm.db2.jcc.a.hd.a(hd.java:1221)
at com.ibm.db2.jcc.c.jb.h(jb.java:142)
at com.ibm.db2.jcc.c.jb.a(jb.java:43)
at com.ibm.db2.jcc.c.w.a(w.java:30)
at com.ibm.db2.jcc.c.cc.g(cc.java:160)
at com.ibm.db2.jcc.a.hd.n(hd.java:1215)
at com.ibm.db2.jcc.a.id.gb(id.java:1780)
at com.ibm.db2.jcc.a.id.d(id.java:2255)
at com.ibm.db2.jcc.a.id.X(id.java:505)
at com.ibm.db2.jcc.a.id.executeQuery(id.java:488)
at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:107)
at org.hibernate.loader.Loader.getResultSet(Loader.java:1183)
at org.hibernate.loader.Loader.doQuery(Loader.java:363)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:203)
at org.hibernate.loader.Loader.doList(Loader.java:1499)
... 6 more
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://opensource.atlassian.com/projects/hibernate/secure/Administrators....
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira