ObjectDB ObjectDB

java.lang.ClassCastException in query results

#1

I have a simple object stored in a ObjectDb file

Stadium

Name (java.lang.String)

Capacity (int)

City (java.lang.String)

 

When i run the following code i get the ClassCastException in the "for (Stadium result : results)" line

TypedQuery<Stadium> query = em.createQuery(
    "SELECT Name, Capacity, City FROM Stadium s", Stadium.class);
List<Stadium> results = query.getResultList();
for (Stadium result : results)
{
     System.out.println("Name: " + result.Name + ", Capacity: " + result.Capacity + ", City: " + result.City);
}

In debug mode i see that the objects in List results are of type Object and not Stadium

What am I doing wrong?

edit
delete
#2

You have to change your query from:

    SELECT Name, Capacity, City FROM Stadium s

to

    SELECT s FROM Stadium s
ObjectDB Support
edit
delete

Reply

To post on this website please sign in.