title: NullPointerException because of the same hibernate constructor
body: <p>I am using <code>hibernate 4.2.0</code>. I am having the following class:</p>
  
  <pre><code>@Entity
  public class TestData {
  
      @Id    
      @GeneratedValue    
      private Long id;
      private String customerNr;
      private String FirstName;
      private String LastName;
  
  
      /**
       * 
       */
      public TestData() {
          super();
      }
  
      /**
       * @param customerNr
       */
      public TestData(String customerNr) {
          super();
          this.customerNr = customerNr;
      }
  
      /**
       * @param id
       * @param customerNr
       * @param firstName
       * @param lastName
       */
      public TestData(Long id, String customerNr, String firstName,
              String lastName) {
          super();
          this.id = id;
          this.customerNr = customerNr;
          FirstName = firstName;
          LastName = lastName;
      }
  
      //getter and setter etc.
  
  }
  </code></pre>
  
  <p>To get all customerNr I am using the following query:</p>
  
  <pre><code>@Transactional
      @SuppressWarnings("all")
      public List&lt;TestData&gt; getCustomerNrFilter(String customerNr) {
          CriteriaBuilder cb = em.getCriteriaBuilder();
          CriteriaQuery&lt;TestData&gt; criteria = cb.createQuery(TestData.class);
          //which table we want to fetch
          final Root root = criteria.from(TestData.class);
          //create statement
          criteria.select(cb.construct(TestData.class, root.get("customerNr"))).distinct(true);
          // Pass the criteria list to the where method of criteria query
          criteria.where(cb.and((Predicate[]) criteriaList.toArray(new Predicate[0])));
          // Order by clause
          criteria.orderBy(cb.asc(root.get("customerNr")));
          return em.createQuery(criteria).getResultList();
      }
  
      public List createWhereCritera(String customerNr, CriteriaBuilder cb,
              final Root root) {
          // This list will contain all Predicates (where clauses)
          List criteriaList = new ArrayList();
          // CustomerNr: where condition: TestData.CustomerNr like '%'
          Predicate predicateFirstName = cb.like(cb.upper(root.get("customerNr")),customerNr);
          criteriaList.add(predicateFirstName);
          return criteriaList;
      }
  </code></pre>
  
  <p>As I see the customerNr uses this constructor to get my data:</p>
  
  <pre><code>/**
   * @param customerNr
   */
  public TestData(String customerNr) {
      super();
      this.customerNr = customerNr;
  }
  
  However, using the same query for `firstName`:
  
  @Transactional
  @SuppressWarnings("all")
  public List&lt;TestData&gt; getCustomerNrFilter(String firstName) {
      CriteriaBuilder cb = em.getCriteriaBuilder();
      CriteriaQuery&lt;TestData&gt; criteria = cb.createQuery(TestData.class);
      //which table we want to fetch
      final Root root = criteria.from(TestData.class);
      //create statement
      criteria.select(cb.construct(TestData.class, root.get("firstName"))).distinct(true);
      // Pass the criteria list to the where method of criteria query
      criteria.where(cb.and((Predicate[]) criteriaList.toArray(new Predicate[0])));
      // Order by clause
      criteria.orderBy(cb.asc(root.get("firstName")));
      return em.createQuery(criteria).getResultList();
  }
  
  public List createWhereCritera(String firstName, CriteriaBuilder cb,
      final Root root) {
      // This list will contain all Predicates (where clauses)
      List criteriaList = new ArrayList();
      // firstName: where condition: TestData.firstName like '%'
      Predicate predicateFirstName = cb.like(cb.upper(root.get("firstName")),firstName);
      criteriaList.add(predicateFirstName);
      return criteriaList;
  }
  
  
  
  However, firstName also tries to use the customerNr constructor to get my data:
  
  /**
   * @param customerNr
   */
  public TestData(String customerNr) {
      super();
      this.customerNr = customerNr;
  }
  </code></pre>
  
  <p>Right now, giving the data back gives me a <code>Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException</code>, because only the <code>customerNr</code> is queried and not the <code>firstName</code>. </p>
  
  <p>I cannot really create two constructors of the same type, because then I would have a <code>duplicated method</code>. Furthermore, leaving the constructor out gives me the exception <code>no appropriate constructor</code></p>
  
  <p>Any recommendations what I should do?</p>
  
  <p><strong>UPDATE 1</strong></p>
  
  <p>Commenting all constructors out gives me:</p>
  
  <pre><code>Unable to locate appropriate constructor on class [com.Application.domain.TestData] [select distinct new com.Application.domain.TestData(generatedAlias0.customerNr) from com.Application.domain.TestData as generatedAlias0 where ( upper(generatedAlias0.customerNr) like :param0 ) and ( upper(generatedAlias0.firstName) like :param1 ) ...
  </code></pre>
  
  <p>I appreciate your replies!</p>
  
  <p><strong>UPDATE 2</strong></p>
  
  <p>My whole stacktrace:</p>
  
  <pre><code>3408 [AWT-EventQueue-0] ERROR org.hibernate.hql.internal.ast.ErrorCounter  -  Unable to locate appropriate constructor on class [com.Application.domain.TestData]
  [cause=org.hibernate.PropertyNotFoundException: no appropriate constructor in class: com.Application.domain.TestData]
  3408 [AWT-EventQueue-0] ERROR org.hibernate.hql.internal.ast.ErrorCounter  -  Unable to locate appropriate constructor on class [com.Application.domain.TestData]
  [cause=org.hibernate.PropertyNotFoundException: no appropriate constructor in class: com.Application.domain.TestData]
   Unable to locate appropriate constructor on class [com.Application.domain.TestData]
  [cause=org.hibernate.PropertyNotFoundException: no appropriate constructor in class: com.Application.domain.TestData]
      at org.hibernate.hql.internal.ast.tree.ConstructorNode.resolveConstructor(ConstructorNode.java:187)
      at org.hibernate.hql.internal.ast.tree.ConstructorNode.prepare(ConstructorNode.java:152)
      at org.hibernate.hql.internal.ast.HqlSqlWalker.processConstructor(HqlSqlWalker.java:1019)
      at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.selectExpr(HqlSqlBaseWalker.java:2279)
      at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.selectExprList(HqlSqlBaseWalker.java:2145)
      at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.selectClause(HqlSqlBaseWalker.java:1451)
      at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:571)
      at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:299)
      at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:247)
      at org.hibernate.hql.internal.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:248)
      at org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:183)
      at org.hibernate.hql.internal.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:136)
      at org.hibernate.engine.query.spi.HQLQueryPlan.&lt;init&gt;(HQLQueryPlan.java:105)
      at org.hibernate.engine.query.spi.HQLQueryPlan.&lt;init&gt;(HQLQueryPlan.java:80)
      at org.hibernate.engine.query.spi.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:168)
      at org.hibernate.internal.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:221)
      at org.hibernate.internal.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:199)
      at org.hibernate.internal.SessionImpl.createQuery(SessionImpl.java:1777)
      at org.hibernate.ejb.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:452)
      at org.hibernate.ejb.criteria.CriteriaQueryCompiler.compile(CriteriaQueryCompiler.java:221)
      at org.hibernate.ejb.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:587)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
      at java.lang.reflect.Method.invoke(Unknown Source)
      at org.springframework.orm.jpa.SharedEntityManagerCreator$SharedEntityManagerInvocationHandler.invoke(SharedEntityManagerCreator.java:241)
      at com.sun.proxy.$Proxy14.createQuery(Unknown Source)
      at com.Application.dao.TestDaoImpl.getCustomerNrTest(TestDaoImpl.java:137)
      at com.Application.dao.TestDaoImpl$$FastClassByCGLIB$$a62bf500.invoke(&lt;generated&gt;)
      at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
      at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:698)
      at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
      at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:96)
      at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:260)
      at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:94)
      at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
      at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:631)
      at com.Application.dao.TestDaoImpl$$EnhancerByCGLIB$$6ca0bd06.getCustomerNrTest(&lt;generated&gt;)
      at com.Application.service.TestServiceImpl.getCustomerNrTest(TestServiceImpl.java:39)
      at com.Application.gui.scenarioSelection.MainTabPanel.placeSelectionWithButtons(MainTabPanel.java:145)
      at com.Application.gui.scenarioSelection.MainTabPanel.createLayout(MainTabPanel.java:119)
      at com.Application.gui.scenarioSelection.MainWindow.createTabBar(MainWindow.java:132)
      at com.Application.gui.scenarioSelection.MainWindow.makeLayout(MainWindow.java:182)
      at com.Application.gui.scenarioSelection.MainWindow.access$1(MainWindow.java:172)
      at com.Application.gui.scenarioSelection.MainWindow$4.run(MainWindow.java:197)
      at java.awt.event.InvocationEvent.dispatch(Unknown Source)
      at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
      at java.awt.EventQueue.access$400(Unknown Source)
      at java.awt.EventQueue$2.run(Unknown Source)
      at java.awt.EventQueue$2.run(Unknown Source)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
      at java.awt.EventQueue.dispatchEvent(Unknown Source)
      at java.awt.EventDispatchThread.pumpOneEventForTests(Unknown Source)
      at java.awt.EventDispatchThread.pumpEventsForTest(Unknown Source)
      at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
      at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
      at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
      at java.awt.EventDispatchThread.run(Unknown Source)
  Cause:
  org.hibernate.PropertyNotFoundException: no appropriate constructor in class: com.Application.domain.TestData
      at org.hibernate.internal.util.ReflectHelper.getConstructor(ReflectHelper.java:372)
      at org.hibernate.hql.internal.ast.tree.ConstructorNode.resolveConstructor(ConstructorNode.java:179)
      at org.hibernate.hql.internal.ast.tree.ConstructorNode.prepare(ConstructorNode.java:152)
      at org.hibernate.hql.internal.ast.HqlSqlWalker.processConstructor(HqlSqlWalker.java:1019)
      at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.selectExpr(HqlSqlBaseWalker.java:2279)
      at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.selectExprList(HqlSqlBaseWalker.java:2145)
      at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.selectClause(HqlSqlBaseWalker.java:1451)
      at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:571)
      at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:299)
      at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:247)
      at org.hibernate.hql.internal.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:248)
      at org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:183)
      at org.hibernate.hql.internal.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:136)
      at org.hibernate.engine.query.spi.HQLQueryPlan.&lt;init&gt;(HQLQueryPlan.java:105)
      at org.hibernate.engine.query.spi.HQLQueryPlan.&lt;init&gt;(HQLQueryPlan.java:80)
      at org.hibernate.engine.query.spi.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:168)
      at org.hibernate.internal.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:221)
      at org.hibernate.internal.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:199)
      at org.hibernate.internal.SessionImpl.createQuery(SessionImpl.java:1777)
      at org.hibernate.ejb.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:452)
      at org.hibernate.ejb.criteria.CriteriaQueryCompiler.compile(CriteriaQueryCompiler.java:221)
      at org.hibernate.ejb.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:587)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
      at java.lang.reflect.Method.invoke(Unknown Source)
      at org.springframework.orm.jpa.SharedEntityManagerCreator$SharedEntityManagerInvocationHandler.invoke(SharedEntityManagerCreator.java:241)
      at com.sun.proxy.$Proxy14.createQuery(Unknown Source)
      at com.Application.dao.TestDaoImpl.getCustomerNrTest(TestDaoImpl.java:137)
      at com.Application.dao.TestDaoImpl$$FastClassByCGLIB$$a62bf500.invoke(&lt;generated&gt;)
      at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
      at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:698)
      at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
      at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:96)
      at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:260)
      at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:94)
      at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
      at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:631)
      at com.Application.dao.TestDaoImpl$$EnhancerByCGLIB$$6ca0bd06.getCustomerNrTest(&lt;generated&gt;)
      at com.Application.service.TestServiceImpl.getCustomerNrTest(TestServiceImpl.java:39)
      at com.Application.gui.scenarioSelection.MainTabPanel.placeSelectionWithButtons(MainTabPanel.java:145)
      at com.Application.gui.scenarioSelection.MainTabPanel.createLayout(MainTabPanel.java:119)
      at com.Application.gui.scenarioSelection.MainWindow.createTabBar(MainWindow.java:132)
      at com.Application.gui.scenarioSelection.MainWindow.makeLayout(MainWindow.java:182)
      at com.Application.gui.scenarioSelection.MainWindow.access$1(MainWindow.java:172)
      at com.Application.gui.scenarioSelection.MainWindow$4.run(MainWindow.java:197)
      at java.awt.event.InvocationEvent.dispatch(Unknown Source)
      at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
      at java.awt.EventQueue.access$400(Unknown Source)
      at java.awt.EventQueue$2.run(Unknown Source)
      at java.awt.EventQueue$2.run(Unknown Source)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
      at java.awt.EventQueue.dispatchEvent(Unknown Source)
      at java.awt.EventDispatchThread.pumpOneEventForTests(Unknown Source)
      at java.awt.EventDispatchThread.pumpEventsForTest(Unknown Source)
      at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
      at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
      at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
      at java.awt.EventDispatchThread.run(Unknown Source)
  Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: org.hibernate.hql.internal.ast.QuerySyntaxException: Unable to locate appropriate constructor on class [com.Application.domain.TestData] [select distinct new com.Application.domain.TestData(generatedAlias0.CustomerNr) from com.Application.domain.TestData as generatedAlias0 where ( upper(generatedAlias0.CustomerNr) like :param0 ) and ( upper(generatedAlias0.City) like :param1 ) and ( upper(generatedAlias0.Country) like :param2 ) and ( upper(generatedAlias0.UseType) like :param3 ) and ( upper(generatedAlias0.ProjStat) like :param4 ) order by generatedAlias0.CustomerNr asc]
      at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1374)
      at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1310)
      at org.hibernate.ejb.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:470)
      at org.hibernate.ejb.criteria.CriteriaQueryCompiler.compile(CriteriaQueryCompiler.java:221)
      at org.hibernate.ejb.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:587)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
      at java.lang.reflect.Method.invoke(Unknown Source)
      at org.springframework.orm.jpa.SharedEntityManagerCreator$SharedEntityManagerInvocationHandler.invoke(SharedEntityManagerCreator.java:241)
      at com.sun.proxy.$Proxy14.createQuery(Unknown Source)
      at com.Application.dao.TestDaoImpl.getCustomerNrTest(TestDaoImpl.java:137)
      at com.Application.dao.TestDaoImpl$$FastClassByCGLIB$$a62bf500.invoke(&lt;generated&gt;)
      at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
      at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:698)
      at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
      at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:96)
      at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:260)
      at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:94)
      at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
      at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:631)
      at com.Application.dao.TestDaoImpl$$EnhancerByCGLIB$$6ca0bd06.getCustomerNrTest(&lt;generated&gt;)
      at com.Application.service.TestServiceImpl.getCustomerNrTest(TestServiceImpl.java:39)
      at com.Application.gui.scenarioSelection.MainTabPanel.placeSelectionWithButtons(MainTabPanel.java:145)
      at com.Application.gui.scenarioSelection.MainTabPanel.createLayout(MainTabPanel.java:119)
      at com.Application.gui.scenarioSelection.MainWindow.createTabBar(MainWindow.java:132)
      at com.Application.gui.scenarioSelection.MainWindow.makeLayout(MainWindow.java:182)
      at com.Application.gui.scenarioSelection.MainWindow.access$1(MainWindow.java:172)
      at com.Application.gui.scenarioSelection.MainWindow$4.run(MainWindow.java:197)
      at java.awt.event.InvocationEvent.dispatch(Unknown Source)
      at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
      at java.awt.EventQueue.access$400(Unknown Source)
      at java.awt.EventQueue$2.run(Unknown Source)
      at java.awt.EventQueue$2.run(Unknown Source)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
      at java.awt.EventQueue.dispatchEvent(Unknown Source)
      at java.awt.EventDispatchThread.pumpOneEventForTests(Unknown Source)
      at java.awt.EventDispatchThread.pumpEventsForTest(Unknown Source)
      at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
      at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
      at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
      at java.awt.EventDispatchThread.run(Unknown Source)
  Caused by: org.hibernate.hql.internal.ast.QuerySyntaxException: Unable to locate appropriate constructor on class [com.Application.domain.TestData] [select distinct new com.Application.domain.TestData(generatedAlias0.CustomerNr) from com.Application.domain.TestData as generatedAlias0 where ( upper(generatedAlias0.CustomerNr) like :param0 ) and ( upper(generatedAlias0.City) like :param1 ) and ( upper(generatedAlias0.Country) like :param2 ) and ( upper(generatedAlias0.UseType) like :param3 ) and ( upper(generatedAlias0.ProjStat) like :param4 ) order by generatedAlias0.CustomerNr asc]
      at org.hibernate.hql.internal.ast.QuerySyntaxException.convert(QuerySyntaxException.java:54)
      at org.hibernate.hql.internal.ast.QuerySyntaxException.convert(QuerySyntaxException.java:47)
      at org.hibernate.hql.internal.ast.ErrorCounter.throwQueryException(ErrorCounter.java:79)
      at org.hibernate.hql.internal.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:255)
      at org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:183)
      at org.hibernate.hql.internal.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:136)
      at org.hibernate.engine.query.spi.HQLQueryPlan.&lt;init&gt;(HQLQueryPlan.java:105)
      at org.hibernate.engine.query.spi.HQLQueryPlan.&lt;init&gt;(HQLQueryPlan.java:80)
      at org.hibernate.engine.query.spi.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:168)
      at org.hibernate.internal.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:221)
      at org.hibernate.internal.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:199)
      at org.hibernate.internal.SessionImpl.createQuery(SessionImpl.java:1777)
      at org.hibernate.ejb.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:452)
      ... 40 more
  </code></pre>
  
  <p><strong>UPDATE 3</strong></p>
  
  <p>Changing my method gives me the following exception:</p>
  
  <pre><code>@Transactional
  @SuppressWarnings("all")
  public List&lt;TestData&gt; getCustomerNrFilter(String firstName) {
      CriteriaBuilder cb = em.getCriteriaBuilder();
      CriteriaQuery&lt;TestData&gt; criteria = cb.createQuery(TestData.class);
      //which table we want to fetch
      final Root root = criteria.from(TestData.class);
      //create statement
      criteria.select(root.get("firstName")).distinct(true);
      // Pass the criteria list to the where method of criteria query
      criteria.where(cb.and((Predicate[]) criteriaList.toArray(new Predicate[0])));
      // Order by clause
      criteria.orderBy(cb.asc(root.get("firstName")));
  
      List&lt;String&gt; resultList = em.createQuery(criteria).getResultList(); // EXCPETION: Type mismatch: cannot convert from List&lt;TestData&gt; to List&lt;String&gt;
  
      return resultList;
  }
  
  public List createWhereCritera(String firstName, CriteriaBuilder cb,
      final Root root) {
      // This list will contain all Predicates (where clauses)
      List criteriaList = new ArrayList();
      // firstName: where condition: TestData.firstName like '%'
      Predicate predicateFirstName = cb.like(cb.upper(root.get("firstName")),firstName);
      criteriaList.add(predicateFirstName);
      return criteriaList;
  }
  </code></pre>