I have the following bit of code:
public List<Folder> findFolderByName(String folderName) { TypedQuery<Folder> byNameQuery = this.entityManager.createQuery("SELECT f FROM Entry f WHERE f.name=:name", Folder.class); return byNameQuery.setParameter("name", folderName).getResultList(); }
I would have assumed that the class parameter would cause results to be restricted to only objects of type Folder (I have a class hierarchy in which both Link and Folder are subclasses of a common root Entry which is where the name parameter occurs).
When I put both a folder and a link with the same name into the database, and execute the above query, I get a List<Folder> with two entries in it according to .size(). If I iterate using a foreach loop, I only get the folder. I can, however do a .get(1) call to fetch the result. Am I doing something wrong to make sure that I only get folders in my result set?