This discussion is archived
2 Replies Latest reply: Apr 27, 2013 5:37 AM by REDO LOG RSS

problem with JPA EntityManager.createQuery()

Currently Being Moderated
Hi all
I am facing a strange problem with entityManager method createQuery(CriteriaQuery) I got the following error:
 Caused by: java.lang.NullPointerException
     at org.eclipse.persistence.internal.jpa.querydef.CriteriaQueryImpl.createCompoundQuery( 
     at org.eclipse.persistence.internal.jpa.querydef.CriteriaQueryImpl.translate(
     at org.eclipse.persistence.internal.jpa.EntityManagerImpl.createQuery(
     at com.sun.enterprise.container.common.impl.EntityManagerWrapper.createQuery(
     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
     at sun.reflect.NativeMethodAccessorImpl.invoke(
     at sun.reflect.DelegatingMethodAccessorImpl.invoke(
     at java.lang.reflect.Method.invoke(
     at com.sun.ejb.containers.BaseContainer.invokeBeanMethod(
     at com.sun.ejb.EjbInvocation.invokeBeanMethod(
     at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(
     at com.sun.ejb.EjbInvocation.proceed(
     at com.sun.ejb.containers.interceptors.SystemInterceptorProxy.doAround(
     at com.sun.ejb.containers.interceptors.SystemInterceptorProxy.aroundInvoke(
     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
     at sun.reflect.NativeMethodAccessorImpl.invoke(
     at sun.reflect.DelegatingMethodAccessorImpl.invoke(
it is reported as a bug but I use the latest EclipseLink api (2.4.x), and the strange thing is when I test the EJB responsible of throwing this exception using an EJB client, everything works fine as expected but integrating this with the web part it just flat away with errors.
Here is the function overrided load since I use Primefaces API for my presentation layer:

     public List<ApplicationDTO> load(
               int first,
               int pageSize,
               String sortedField,
               com.mobiwigo.common.dataaccess.IDataAccessProxy.SortOrder sortOrder,
               Map<String, String> filters) {

          CriteriaBuilder cb = entityManager.getCriteriaBuilder();
          CriteriaQuery<ApplicationDTO> q = cb.createQuery(ApplicationDTO.class);
          Root<Application> a = q.from(Application.class);

          applyFilter(a, cb, q, filters);
          applySort(cb, q, a, sortedField, sortOrder);

, a));

          return entityManager.createQuery(q).setFirstResult(first)
the functions applySort and applyFilter are
private void applySort(CriteriaBuilder cb, CriteriaQuery<ApplicationDTO> q,
               Root<Application> a, String sortedField, SortOrder sortOrder) {
        if(sortedFiled != null){
          if (sortOrder == SortOrder.ASC) {



          if (sortOrder == SortOrder.DESC) {


     private void applyFilter(Root<Application> a, CriteriaBuilder cb,
               CriteriaQuery<ApplicationDTO> q, Map<String, String> filters) {

        if(filters != null){

          List<Predicate> predicates = new ArrayList<Predicate>();

          for (String s : filters.keySet()) {

               if (a.get(s) != null) {

                    predicates.add(<String> get(s),
                              "%" + filters.get(s) + "%"));

          q.where(cb.and(predicates.toArray(new Predicate[predicates.size()])));




  • Correct Answers - 10 points
  • Helpful Answers - 5 points