-->
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: EJB, EntityMangaer query with count problem.
PostPosted: Mon Jun 15, 2009 5:06 am 
Newbie

Joined: Mon Jun 15, 2009 5:03 am
Posts: 1
Hi all.
i've some problem. i've a method inside my ejb.

(try to find out the similar item, the value is setted static to 1 for the trials)

Code:
    public List<Item> findSimilarItem(Item item) {
        ArrayList<Item> result = new ArrayList<Item>();
        Long resulto = (Long) em.createQuery("" + "SELECT COUNT(*) FROM item").getSingleResult();
        System.out.println("contatore " + resulto);
        ArrayList idList = (ArrayList) em.createQuery("" +
                "SELECT data.idItem FROM ( " +
                    "SELECT idItem , COUNT(*) AS howmany FROM ( " +
                        "SELECT idorder " +
                            "FROM bought " +
                            "WHERE idItem = 1 " +
                        ")AS these " +
                        "INNER JOIN bought " +
                        "ON bought.idOrder = these.idOrder " +
                        "AND bought.idItem <> 1 " +
                        "GROUP BY iditem " +
                    ") AS data " +
                "ORDER BY data.howmany DESC LIMIT 5)").getResultList();
        //                .getResultList();
        for (int i = 0; i < idList.size(); i++) {
            Integer idItem = (Integer) idList.get(i);
            result.add(em.find(Item.class, idItem));
        }


        return result;
   


when i call this method the result is:
the webpage
Code:
javax.ejb.EJBException: java.lang.IllegalArgumentException: org.hibernate.hql.ast.QuerySyntaxException: unexpected token: ( near line 1, column 25 [SELECT data.idItem FROM ( SELECT idItem , COUNT(*) AS howmany FROM ( SELECT idorder FROM entity.Bought WHERE idItem = 1 )AS these INNER JOIN bought ON bought.idOrder = these.idOrder AND bought.idItem <> 1 GROUP BY iditem ) AS data ORDER BY data.howmany DESC LIMIT 5)]
   org.jboss.ejb3.tx.Ejb3TxPolicy.handleExceptionInOurTx(Ejb3TxPolicy.java:77)
   org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:83)

in the console
Code:
11:01:48,546 ERROR [PARSER] line 1:25: unexpected token: (
11:01:48,562 ERROR [PARSER] line 1:43: unexpected token: COUNT


any idea?

thanks


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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.