Skip to main content

nativeQuery vs namedQuery

No replies
clros
Offline
Joined: 2013-08-07
Points: 0

Hi!

I am trying this code (GlassFish Application server):

@WebMethod(operationName = "readClassByIdAS")
@WebResult(name="outputClasses")
public java.util.List readClassByIdAS()
{
java.util.List res;

try
{
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)