-->
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: Sql query conversion
PostPosted: Mon Sep 03, 2012 11:24 am 
Newbie

Joined: Thu Dec 21, 2006 11:01 am
Posts: 12
Hi,

I have an SQL query that I would like to convert into a criteria to use it into my persistancy layer.
That's the query :

Code:
select last_name
  from member
  where
    member.end_date > SYSDATE
  group by member.last_name
  having count(member.last_name) >1;

I already try a lot a combinations, but there is no result that would be good for me ... This is my code :

Code:
      
Criteria criteria = getSession(false).createCriteria(Member.ENTITY_NAME);
      criteria.setProjection(Projections.projectionList()
            .add(Projections.groupProperty("lastName"))
            .add(Projections.count("lastName").as("cptLastName"))
            );
      criteria.add(Restrictions.ge("endDate", now))
            .add(Restrictions.le("startDate", now))
            //.add(Restrictions.gt("cptLastName", new Integer(1)))[/color]
            .addOrder(Order.asc("lastName"))
      ;

With writing it with the comment line, I have an objects list that contains the name and the number of times that the name appears in the database. But when i would like to decomment it, this the error :
java.sql.SQLException: ORA-00904: "Y1_": invalid identifier

I think I'm not far of the solution but is there anabody to help me ?
If you have questions, don't hesitate to tell me.

Thanks in advance


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.