1

When i use query.getResultList(), THE COMPILER gives a warning.

My Code is:

Query query = entityManager.createQuery("SELECT s.ledger,sum(s.DebitAmt),sum(s.CreditAmt) FROM  VouchersDetailsPO as s WHERE s.Ledger='"+ledgerName+"' GROUP BY s.Ledger");
List<Object[]> results = query.getResultList();

Warning text is:

1.Start the 'Infer Generic Type Arguments' refactoring

2.Add SupressWarnings 'uncheck'

But I don't want to use SupressWarnings annotation.

Neil Stockton
  • 11,383
  • 3
  • 34
  • 29
rocky
  • 103
  • 1
  • 3
  • 10

1 Answers1

1

You need to help compiler with type inference. The solution is to replace

Query query = entityManager.createQuery("...");

with

TypedQuery<Object[]> query = entityManager.createQuery("...", Object[].class);
wypieprz
  • 7,981
  • 4
  • 43
  • 46
  • getting warning after using your code: The method createQuery(String) in the type EntityManager is not applicable for the arguments (String, Class) – rocky Mar 30 '15 at 14:34
  • I can hardly believe it. What JPA / Hibernate version are you using ? – wypieprz Mar 31 '15 at 09:42