title: java.lang.IllegalArgumentException: The attribute [A] from the managed type [T] is not present
body: <p>I'm trying to do a search page that retrieves some data from my database using JPA 2.0 Criteria API. I'm getting the same exception error everytime I try to do the search.</p>
  
  <p>Here is my search method:</p>
  
  <pre><code>public List&lt;Matches&gt; search(SearchCommercialsDTO searchCommercialsDTO) {
  
      CriteriaBuilder builder = em.getCriteriaBuilder();
      CriteriaQuery&lt;Matches&gt; criteria = builder.createQuery( Matches.class );
      Root&lt;Matches&gt; matchesRoot = criteria.from( Matches.class );
      criteria.select( matchesRoot );
  
      List&lt;Predicate&gt; predicateList = new ArrayList&lt;Predicate&gt;();
  
      Predicate date, equipmentName, channelCode, advertiserName, agencyName, productName, duration;
  
      if(!ObjectUtil.isEmpty(searchCommercialsDTO.getEquipmentName())) {
          equipmentName = builder.like(matchesRoot.get("ID_RECORDER_FILES.EQUIPMENT_NAME").as(String.class), searchCommercialsDTO.getEquipmentName());
          predicateList.add(equipmentName);
      }
      if(!ObjectUtil.isEmpty(searchCommercialsDTO.getChannelCode())) {
          channelCode = builder.equal(matchesRoot.get("ID_RECORDER_FILES.CHANNEL_CODE"), searchCommercialsDTO.getChannelCode());
          predicateList.add(channelCode);
      }
      if(!ObjectUtil.isEmpty(searchCommercialsDTO.getAdvertiserName())) {
          advertiserName = builder.equal(matchesRoot.get("ID_SOURCE_MATERIAL.ADVERTISER_NAME"), searchCommercialsDTO.getAdvertiserName());
          predicateList.add(advertiserName);
      }
      if(!ObjectUtil.isEmpty(searchCommercialsDTO.getAgencyName())) {
          agencyName = builder.equal(matchesRoot.get("ID_SOURCE_MATERIAL.AGENCY_NAME"), searchCommercialsDTO.getAgencyName());
          predicateList.add(agencyName);
      }
      if(!ObjectUtil.isEmpty(searchCommercialsDTO.getProductName())) {
          productName = builder.equal(matchesRoot.get("ID_SOURCE_MATERIAL.PRODUCT_NAME"), searchCommercialsDTO.getProductName());
          predicateList.add(productName);
      }
  
      Predicate[] predicates = new Predicate[predicateList.size()];
      predicateList.toArray(predicates);
      criteria.where(predicates);
  
      return em.createQuery(criteria).getResultList();
  }
  </code></pre>
  
  <p>When it tries to execute this part:</p>
  
  <pre><code>equipmentName = builder.like(matchesRoot.get("ID_RECORDER_FILES.EQUIPMENT_NAME").as(String.class), searchCommercialsDTO.getEquipmentName());
  </code></pre>
  
  <p>It throws the following exception:</p>
  
  <pre><code>java.lang.IllegalArgumentException: The attribute [ID_RECORDER_FILES.EQUIPMENT_NAME] from the managed type [EntityTypeImpl@112477145:Matches [ javaType: class net.checkmidia.auditoria.entity.Matches descriptor: RelationalDescriptor(net.checkmidia.auditoria.entity.Matches --&gt; [DatabaseTable(MATCHES)]), mappings: 12]] is not present.
      at org.eclipse.persistence.internal.jpa.metamodel.ManagedTypeImpl.getAttribute(ManagedTypeImpl.java:147)
      at org.eclipse.persistence.internal.jpa.querydef.FromImpl.get(FromImpl.java:312)
      at net.checkmidia.auditoria.business.MatchesBO.search(MatchesBO.java:50)
      at net.checkmidia.auditoria.session.MatchesSession.searchMatches(MatchesSession.java:47)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:597)
      at org.glassfish.ejb.security.application.EJBSecurityManager.runMethod(EJBSecurityManager.java:1052)
      at org.glassfish.ejb.security.application.EJBSecurityManager.invoke(EJBSecurityManager.java:1124)
      at com.sun.ejb.containers.BaseContainer.invokeBeanMethod(BaseContainer.java:5388)
      at com.sun.ejb.EjbInvocation.invokeBeanMethod(EjbInvocation.java:619)
      at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:800)
      at com.sun.ejb.EjbInvocation.proceed(EjbInvocation.java:571)
      at org.jboss.weld.ejb.SessionBeanInterceptor.aroundInvoke(SessionBeanInterceptor.java:42)
      at sun.reflect.GeneratedMethodAccessor126.invoke(Unknown Source)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:597)
      at com.sun.ejb.containers.interceptors.AroundInvokeInterceptor.intercept(InterceptorManager.java:861)
      at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:800)
      at com.sun.ejb.EjbInvocation.proceed(EjbInvocation.java:571)
      at com.sun.ejb.containers.interceptors.SystemInterceptorProxy.doAround(SystemInterceptorProxy.java:162)
      at com.sun.ejb.containers.interceptors.SystemInterceptorProxy.aroundInvoke(SystemInterceptorProxy.java:144)
      at sun.reflect.GeneratedMethodAccessor72.invoke(Unknown Source)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:597)
      at com.sun.ejb.containers.interceptors.AroundInvokeInterceptor.intercept(InterceptorManager.java:861)
      at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:800)
      at com.sun.ejb.containers.interceptors.InterceptorManager.intercept(InterceptorManager.java:370)
      at com.sun.ejb.containers.BaseContainer.__intercept(BaseContainer.java:5360)
      at com.sun.ejb.containers.BaseContainer.intercept(BaseContainer.java:5348)
      at com.sun.ejb.containers.EJBLocalObjectInvocationHandler.invoke(EJBLocalObjectInvocationHandler.java:214)
      ... 51 more
  </code></pre>
  
  <p>How is this caused and how can I solve it?</p>