Back Forum Reply New

Problem in using HibernateTemplate.findByNamedQuery()

I am facing an issue in Hibernate which is on HibernateTemplate.findByNamedQuery()
We have configured the query in our hbm as,
lt;query name=quot;ItemImpl.findItemByKeywordsquot;gt;       lt;![CDATA[from ItemImpl as item inner join item.itemMeta as meta inner join meta.keywords as keywords where keywords.name in ( ? )]]gt;   lt;/querygt;
And in our implementation class we are calling our query using
hibernateTemplate.findByNamedQuery(quot;ItemImpl.findI  temByKeywordsquot;, Object);
The problem is, if we pass a string value like 'keyword1', it returns the exact matches found in the DB.
items = hibernateTemplate.findByNamedQuery(quot;AssessmentItem  Impl.findItemByKeywordsquot;, quot;keyword1quot;);
Suppose if we pass the value as quot;'keyword1','keyword2'quot;, it returns zero.
items = hibernateTemplate.findByNamedQuery(quot;AssessmentItem  Impl.findItemByKeywordsquot;, quot;'keyword1','keyword2'quot;);
I am not able to rectify this problem. So I'm in need of your help.

so, what is the query -

AssessmentItemImpl.findItemByKeywords

lt;query name=quot;AssesmentItemImpl.findItemByKeywordsquot;gt;
lt;![CDATA[from ItemImpl as item inner join item.itemMeta as meta inner join meta.keywords as keywords where keywords.name in ( ? )]]gt;
lt;/query

try....Code:
query name=quot;ItemImpl.findItemByKeywordsquot;gt;
lt;![CDATA[from ItemImpl as item inner join item.itemMeta as meta inner join meta.keywords as keywords where keywords.name in ( :params )]]gt;
lt;/querygt;
and Code:
String[] params={quot;keyword1quot;,quot;keyword2quot;};
items = hibernateTemplate.findByNamedQueryAndNamedParam(quot;AssessmentItem Impl.findItemByKeywordsquot;, quot;paramsquot; , params);Thanks a lot. It works.
¥
Back Forum Reply New