Search code examples
javahibernatenamed-query

Check if a specific named parameter exists or not in hibernate named query


I am trying to develop a application where I have a common DAO as EntityDao.

That class has a method executeNamedQuery as follows.

public List executeNamedQuery(String queryName) {
        Query query = getHibernateUtil().getCurrentSession().getNamedQuery(queryName);
        list = query.list();
        return list;
}

I have several named query in different classes. One example is given as follows.

@NamedQueries({
    @NamedQuery(
    name = "BookList",
    query = "FROM Book AS B WHERE cntrl1=:CNTRL_1"
    )
}) 

Aslo some of the queries does not have that where clause, or some of those have a where clause but does not have CNTRL_1 as named parameter.

I have a common CNTRL_1 value that I want to set from common EntityDao executeNativeQuery method with setParameter. But before that I want to determine is there any named parameter exists with name CNTRL_1 or not in the named query.

How to do that? Please help.


Solution

  • Did you try getNamedParameters() already?