Hi,
I'm new to hibernate and have found a few issues that I was hoping I could maybe get some guidance for:
I'm using annotations and I've created a bean (DealerLocation) and mapped the database Columns to the corresponding variables in my bean. I have a method that returns a List<DealerLocation> for that bean, which executes an HQL query.
The following list works and returns a List populated with <DealerLocation> Objects, which is great: locations = getSessionFactory().getCurrentSession().createQuery( "from DealerLocation as locations order by locations.country, locations.state, locations.city").list();
However, if I modify the Query to use a select distinct instead (like this):
locations = getSessionFactory().getCurrentSession().createQuery( "select distinct country, state, city from DealerLocation as locations order by locations.country, locations.state, locations.city").list();
I get the right number of records back (if I check locations.size()) but when I try and iterate through the List (using for (DealerLocation dl : locations) { ... }), I get this error:
java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to com.myapp.bean.DealerLocation
Am somewhat confused (a) as to why modifying the query suddenly breaks the casting; and (b) as to how I can iterate through the array of Objects[] to get my information into DealerLocation Objects (if I have to do that).
Could anyone here offer any advice / asssistance as to what I may be doing wrong? Or what I may need to do in order to get the correct results back?
Many thanks. A
|