Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[eclipselink-users] Non-Entity types and TypedQuery / ClassCastExceptions

Hi all,

I'm playing around with non-entity return types at the moment and
constantly run into java.lang.ClassCastExceptions ..

Given:
 TypedQuery<CountryHolder> query = entityManager.createQuery("SELECT
v.country, COUNT(v.country) AS cnt FROM Visit v GROUP BY v.country
ORDER BY COUNT(v.country)", CountryHolder.class);
 List<CountryHolder> results = query.getResultList();

keeps returning a list of Object[] but not the desired pojo (which has
a public non-arg and a  public CountryHolder(String country, Integer
cnt) constructor ...)

Every try to iterate the List and cast to anything else than Object fails ...

Running that query against the DB returns the expected two columns mit
the names country and cnt ...

Turning sql logging on gives an indication that the following sql is
send to the database .. which in fact skips the "as cnt" part ...

SELECT COUNTRY, COUNT(COUNTRY) FROM VISIT GROUP BY COUNTRY ORDER BY
COUNT(COUNTRY) ASC

I'm running GlassFish Server Open Source Edition 3.1.2.2 with Eclipse
Persistence Services - 2.3.2.v20111125-r10461 against Apache Derby
Network Client JDBC Driver  Version: 10.8.2.2 - (1181258)

Any ideas highly appreciated!

Thanks,
- Markus


Back to the top