-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: JPA 2.0 Criteria order by path
PostPosted: Fri Jan 29, 2010 5:38 pm 
Beginner
Beginner

Joined: Fri Nov 11, 2005 4:35 pm
Posts: 23
Hi,

I have problems sorting a criteria.

Code:
   CriteriaBuilder builder = getEntityManager().getCriteriaBuilder();
   CriteriaQuery<Object[]> criteria = builder.createQuery(Object[].class);
   Root<GloCompany> gloCompanyRoot = criteria.from(GloCompany.class);

   Join<GloCompany,GloCompanyAddress> gloCompanyAddresses = gloCompanyRoot.join(GloCompany_.gloCompanyAddresses, JoinType.LEFT);
   Join<GloCompanyAddress,GloCompanyAddressLocale> gloCompanyAddressLocales = gloCompanyAddresses.join("gloCompanyAddressLocales", JoinType.LEFT);

   criteria.orderBy(builder.asc(gloCompanyRoot.get("gloCompanyAddresses.gloCompanyAddressLocales.name")));



I get the following error on line:
criteria.orderBy(builder.asc(gloCompanyRoot.get("gloCompanyAddresses.gloCompanyAddressLocales.name")));

Code:
java.lang.NullPointerException
   at org.hibernate.ejb.criteria.path.AbstractPathImpl.unknownAttribute(AbstractPathImpl.java:110)
   at org.hibernate.ejb.criteria.path.AbstractPathImpl.locateAttribute(AbstractPathImpl.java:218)
   at org.hibernate.ejb.criteria.path.AbstractPathImpl.get(AbstractPathImpl.java:189)
   at ....


I know i can do:
criteria.orderBy(builder.asc(gloCompanyAddressLocales .get("name")));
This will work.

I'm looking for a function to order a path given as string. (worked in hibernate criteria)

Thanks in advance,
Pieter Pareit


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.