-->
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.  [ 3 posts ] 
Author Message
 Post subject: DISTINCT query not working
PostPosted: Wed Mar 02, 2011 7:56 am 
Newbie

Joined: Wed Aug 18, 2010 6:43 am
Posts: 10
Hi All
Can someone please have a look at this query, I can not understand the error. All I'm trying to do is select all manufacturers from Product table with DISTINCT clause. The Product table has an attribute called 'String manufacturer' . Why am I getting this error ???

Code:
@NamedQuery(name = "Product.findByManu", query = "SELECT DISTINCT p.manufacturer FROM Product p WHERE p.categoryId.categoryId = :categoryId")

Query Manager
Code:
public List<Product> getProductsByManu(Integer categoryId) {
      em.getTransaction().begin();
      List<Product> prods = em.createNamedQuery("Product.findByManu")
            .setParameter("categoryId", categoryId).getResultList();
      em.getTransaction().commit();
      return prods;
   }

Error
Code:
javax.servlet.ServletException: The class 'java.lang.String' does not have the property 'manufacturer'.


Many thanks
Zed


Top
 Profile  
 
 Post subject: Re: DISTINCT query not working
PostPosted: Mon Mar 07, 2011 10:28 am 
Newbie

Joined: Wed Aug 18, 2010 6:43 am
Posts: 10
Can anyone help please !!! I'm still stuck :(


Top
 Profile  
 
 Post subject: Re: DISTINCT query not working
PostPosted: Mon Mar 07, 2011 1:56 pm 
Newbie

Joined: Mon Mar 07, 2011 6:32 am
Posts: 3
Try,

criteria.setProjection(Projections.distinct(Projections.property("id")));


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

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.