Skip to main content

nativeQuery vs namedQuery

Please note these forums are being decommissioned and use the new and improved forums at
No replies
Joined: 2013-08-07


I am trying this code (GlassFish Application server):

@WebMethod(operationName = "readClassByIdAS")
public java.util.List readClassByIdAS()
java.util.List res;

Query query = manager.createNativeQuery("SELECT c FROM Classe c",Classe.class);
// Query query = manager.createNamedQuery("Classe.findAll");
res = query.getResultList();
catch(Exception e){res = null;}
return res;

the "Classe" class is an entity class from database.

Why the namedQuery work well and the nativeQuery don't work (it return an empty java.util.List<>) ? The nativeQuery is identical to Classe.findAll namedQuery)