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