Caused by: org.hibernate.QueryException: All named parameters have not been set: when using hibernate templates


Sumav

Getting this exception when using hibernate template in spring.

Caused by: org.hibernate.QueryException: Not all named parameters have been set: [roledesc, sapid, pass] [
        select u from Role as r left join r.users as u where u.sapid=:sapid and u.pass=:pass and r.roledesc=:roledesc
    ]
    at org.hibernate.impl.AbstractQueryImpl.verifyParameters(AbstractQueryImpl.java:291)
    at org.hibernate.impl.AbstractQueryImpl.verifyParameters(AbstractQueryImpl.java:275)
    at org.hibernate.impl.QueryImpl.list(QueryImpl.java:75)
    at org.springframework.orm.hibernate3.HibernateTemplate$33.doInHibernate(HibernateTemplate.java:988)
    at org.springframework.orm.hibernate3.HibernateTemplate$33.doInHibernate(HibernateTemplate.java:1)
    at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:406)
    ... 30 more

Here is the class I am trying to get the named query:

public class LoginDaoImpl extends AbstractDaoImpl implements LoginDao {

    private static final Logger LOGGER = Logger.getLogger(LoginDaoImpl.class);

    @Override
    public User loginCheck(User user, Role role) {
        LOGGER.debug("Inside validate user:" + user.getPass());

        user.setName("");

        List<User> employee = new ArrayList<User>();

        Query query = (Query) template.findByNamedQuery("findRoleforaUser");

        query.setString("sapid", user.getSapid());
        query.setString("pass", user.getPass());
        query.setString("roledesc", role.getRoledesc());
            employee = query.list();
            if(employee == null)
            {
                user.setName("");
            }

            else if(employee.isEmpty())
            {
                user.setName("");
            }


            else if (!(user.getPass().equals(employee.get(0).getPass())))

                LOGGER.info("No match found!");
            else {
                user.setName( employee.get(0).getName());
                LOGGER.debug("\nUser \"" + employee.get(0).getName()
                        + "\" found and login is successful ");

            }


                return user;
    }

}

Here is my .hbm file content with named queries defined:

<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-mapping SYSTEM "D:\My HCL JEE Progs\CBA_Quiz\src\dtd\hibernate-mapping-3.0.dtd">
<hibernate-mapping>
    <class name="com.hcl.cba.payments.domain.Role" table="roles">
        <id name="roleid" type="int" column="ROLEID" />
        <property name="roledesc" type="string" column="ROLEDESC" />
        <set name="users" cascade="all">
            <key column="roleid" />
            <one-to-many class="com.hcl.cba.payments.domain.User" />
        </set>
    </class>
    <query name="findRoleforaUser">
        <![CDATA[select u from Role as r left join r.users as u where u.sapid=:sapid and u.pass=:pass and r.roledesc=:roledesc]]>
    </query>
</hibernate-mapping>

PS: I tried running/accessing the query without the hibernate template and it worked fine, and I also set the variable in the same way:

      Query query = session.findByNamedQuery("findRoleforaUser");
      query.setString("sapid", user.getSapid());
      query.setString("pass", user.getPass());
      query.setString("roledesc", role.getRoledesc());            
      employee =query.list();
Predrag Maric

this should work

List<User> employees = new ArrayList<User>();
String[] paramNames = { "sapid", "pass", "roledesc" };
Object[] values = { user.getSapid(), user.getPass(), role.getRoledesc() };
employees = template.findByNamedQueryAndNamedParam("findRoleforaUser", paramNames, values);

Related


All named parameters have not been set: [:int]

Franco I use PostgreSQL and hibernate I have this function: public List getMaxNumOrder (){ String query= "select max(NULLIF(split_part(num_ordre_decision, '/', 3), '')::int) from decision"; SQLQuery sqlQuery = this.getSession().createSQLQuery

Hibernate: org.hibernate.QueryException

Criano: I have an org.hibernate.QueryException and I'm having a hard time understanding why. The property langue_id which hibernate condition cannot resolve is defined in my entity Conditionnement. stack trace Caused by: org.hibernate.QueryException: could not

Hibernate: org.hibernate.QueryException

Criano: I have an org.hibernate.QueryException and I'm having a hard time understanding why. The property langue_id which hibernate condition cannot resolve is defined in my entity Conditionnement. stack trace Caused by: org.hibernate.QueryException: could not

Hibernate: org.hibernate.QueryException

Criano: I have an org.hibernate.QueryException and I'm having a hard time understanding why. The property langue_id which hibernate condition cannot resolve is defined in my entity Conditionnement. stack trace Caused by: org.hibernate.QueryException: could not

Hibernate: org.hibernate.QueryException

Criano: I have an org.hibernate.QueryException and I'm having a hard time understanding why. The property langue_id which hibernate condition cannot resolve is defined in my entity Conditionnement. stack trace Caused by: org.hibernate.QueryException: could not

Not all named parameters have been set under certain conditions

Amit Sharad I have used the following query in Hibernate i.e. createSQLQuery SELECT to_char(dd, 'Mon YYYY') FROM generate_series('2013-01-01'::date, date_trunc('month', now()), '1 month') as dd When run in PostgreSQL it produces output "January 2013" "Februa

Not all named parameters have been set under certain conditions

Amit Sharad I have used the following query in Hibernate i.e. createSQLQuery SELECT to_char(dd, 'Mon YYYY') FROM generate_series('2013-01-01'::date, date_trunc('month', now()), '1 month') as dd When run in PostgreSQL it produces output "January 2013" "Februa

Not all named parameters have been set under certain conditions

Amit Sharad I have used the following query in Hibernate i.e. createSQLQuery SELECT to_char(dd, 'Mon YYYY') FROM generate_series('2013-01-01'::date, date_trunc('month', now()), '1 month') as dd When run in PostgreSQL it produces output "January 2013" "Februa

QueryException on Hibernate when using CriteriaBuilder.function()

Miguel Vidal I am trying to do a simple select using JPA: SELECT POW(2, 10) FROM COUNTRY So, I try: EntityManager em = getEM(); CriteriaBuilder cb = em.getCriteriaBuilder( ); CriteriaQuery< Object > cq = cb.createQuery( ); cq.from( Country.class ); cq.multise

Using hibernate named parameters twice

DmiN: Suppose I have the following HQL EntityManager.createQuery("SELECT a FROM a WHERE a.b = :par OR a.c = :par").setParameter("par", obj); doesn't seem to work. Has anyone solved this problem using only one parameter? Devia: setParameter(String name,Object

Using hibernate named parameters twice

DmiN: Suppose I have the following HQL EntityManager.createQuery("SELECT a FROM a WHERE a.b = :par OR a.c = :par").setParameter("par", obj); doesn't seem to work. Has anyone solved this problem using only one parameter? Devia: setParameter(String name,Object

Using hibernate named parameters twice

DmiN: Suppose I have the following HQL EntityManager.createQuery("SELECT a FROM a WHERE a.b = :par OR a.c = :par").setParameter("par", obj); doesn't seem to work. Has anyone solved this problem using only one parameter? Devia: setParameter(String name,Object

Using hibernate named parameters twice

DmiN: Suppose I have the following HQL EntityManager.createQuery("SELECT a FROM a WHERE a.b = :par OR a.c = :par").setParameter("par", obj); doesn't seem to work. Has anyone solved this problem using only one parameter? Devia: setParameter(String name,Object

Using hibernate named parameters twice

DmiN: Suppose I have the following HQL EntityManager.createQuery("SELECT a FROM a WHERE a.b = :par OR a.c = :par").setParameter("par", obj); doesn't seem to work. Has anyone solved this problem using only one parameter? Devia: setParameter(String name,Object