Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 416
Partha Sarathi Ghosh Avatar asked Oct 18 '22 21:10

Partha Sarathi Ghosh


1 Answers

Did you try getNamedParameters() already?

like image 167
Betlista Avatar answered Oct 30 '22 04:10

Betlista