Java Persistence: Cast to something the result of Query.getResultList() ?

Posted by GuiSim on Stack Overflow See other posts from Stack Overflow or by GuiSim
Published on 2009-06-05T18:34:55Z Indexed on 2010/05/08 17:18 UTC
Read the original article Hit count: 190

Filed under:
|
|
|

Hey everyone, I'm new to persistence / hibernate and I need your help.

Here's the situation. I have a table that contains some stuff. Let's call them Persons. I'd like to get all the entries from the database that are in that table.

I have a Person class that is a simple POJO with a property for each column in the table (name, age,..)

Here's what I have :

Query lQuery = myEntityManager.createQuery("from Person")
List<Person> personList = lQuery.getResultList();

However, I get a warning saying that this is an unchecked conversion from List to List<Person>

I thought that simply changing the code to

Query lQuery = myEntityManager.createQuery("from Person")
List<Person> personList = (List<Person>)lQuery.getResultList();

would work.. but it doesn't.

Is there a way to do this ? Does persistence allow me to set the return type of the query ? (Through generics maybe ? )

© Stack Overflow or respective owner

Related posts about persistence

Related posts about hibernate