Hibernate native query creation returns empty result
I have this method in my DAO class:
public List<Protocolo> buscarProtocolos(int situacao){
List<Protocolo> protocolos = null;
protocolosPorSitucao = null;
String sql = "select * from hibernatedb.protocolo where situacao_id = ?";
em = HibernateManager.getEntityManager();
protocolosPorSitucao = em.createNativeQuery(sql, Protocolo.class);
protocolosPorSitucao.setParameter(1, situacao);
em.getTransaction().begin();
logger.info("Buscando protocolos por situacao : "+ situacao);
protocolos = (List<Protocolo>) protocolosPorSitucao.getResultList();
logger.info("Protocolos encontrados: "+protocolos.size());
em.getTransaction().commit();
em.close();
return protocolos;
}
This query select * from hibernatedb.protocolo where situacao_id = 1
returns one row when executed in pgAdmin3, but hibernate returns 0 rows. Here's the log generated from hibernation:
Hibernate: select * from hibernatedb.protocolo where situacao_id = ?
0
This means hibernate returned 0 results because my list is empty.
Where is the error in this code?
PS: when creating NativeQueries, I also need to install the database. Is this because NativeQuery ignores configs set in persistence.xml
?
+3
source to share
No one has answered this question yet
Check out similar questions: