How to work with Hibernate Named query and Criteria object together
I defined Hibernate named query,So i am getting this query using criteria.getNamedQuery(),
Here i want to integrate this with criteria object,so开发者_运维技巧 that i will put extra constraints.
Any hints please.
Regards, Raju
You shouldn't add clauses to a pre-built named query, you can create any query you want with the SqlQuery class.
You could also change your named query and add the like clause.
session.getNamedQuery("findStuff").setString("likeWhat", value);
where your query would be
select * from sometable where somevalue like :likeWhat
Edit:
You could also do something like
Query q = session.getNamedQuery("findStuff");
String query = q.getQueryString(); // the sql statement
query += " and findStuff like :likeWhat"; // add your clause
q = session.createQuery(query);
q.setParameter("likeWhat", value);
But I think that's hacky.
精彩评论