Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » problem with entityManager.createQuery(CriteriaQuery q)
problem with entityManager.createQuery(CriteriaQuery q) [message #1047710] Tue, 23 April 2013 14:51 Go to next message
rachid elmaazouz is currently offline rachid elmaazouzFriend
Messages: 1
Registered: April 2013
Junior Member
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(CriteriaQueryImpl.java:543) 
	at org.eclipse.persistence.internal.jpa.querydef.CriteriaQueryImpl.translate(CriteriaQueryImpl.java:715)
	at org.eclipse.persistence.internal.jpa.EntityManagerImpl.createQuery(EntityManagerImpl.java:1313)
	at com.sun.enterprise.container.common.impl.EntityManagerWrapper.createQuery(EntityManagerWrapper.java:500)
	at com.mobiwigo.pay.webportal.subscription.ApplicationManagementService.load(ApplicationManagementService.java:51)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:601)
	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:5367)
	at com.sun.ejb.EjbInvocation.invokeBeanMethod(EjbInvocation.java:619)
	at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:801)
	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.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)





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:


@Override
	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);

		q.select(JPAUtils.constructApplicationDTO(cb, a));

		return entityManager.createQuery(q).setFirstResult(first)
				.setMaxResults(pageSize).getResultList();
	}





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) {

			q.orderBy(cb.asc(a.get(sortedField)));

		}

		if (sortOrder == SortOrder.DESC) {
			q.orderBy(cb.desc(a.get(sortedField)));
		}
            }

	}

	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(cb.like(a.<String> get(s),
						"%" + filters.get(s) + "%"));
			}
		}

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

           }

	}


Re: problem with entityManager.createQuery(CriteriaQuery q) [message #1049350 is a reply to message #1047710] Thu, 25 April 2013 18:43 Go to previous message
Chris Delahunt is currently offline Chris DelahuntFriend
Messages: 1389
Registered: July 2009
Senior Member
The bug I believe you are refering to is https://bugs.eclipse.org/bugs/show_bug.cgi?id=340280 and I've verified is fixed in 2.4.x stream. What version/build are you using? You can verify the version by enabling Eclipselink logging I believe to fine, and it will be logged at login. The web component might be using a different version of the EclipseLink jar from the one that is working.

http://wiki.eclipse.org/EclipseLink/Examples/JPA/Logging

[Updated on: Thu, 25 April 2013 18:44]

Report message to a moderator

Previous Topic:insert always null on embedded fields
Next Topic:No data persisted to database with new JPA-RS libs
Goto Forum:
  


Current Time: Fri Apr 26 11:33:02 GMT 2024

Powered by FUDForum. Page generated in 0.03630 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top