Hibernate returns list of nulls although executed SQL returns values
I've set the Log level of hibernate to TRACE and found the problem. It was actually a mapping/logic/database error. The primary key consisted of two columns (according to the entity class) and one of these columns was nullable. However a primary key can never be nullable. Therefore hibernate always returned null.
If you have not set a custom (and buggy) ResultTransformer, my second best guess is that your debugger is lying to you. Does you code actually receives a list of null?
Also make sure to test with the code you are showing is. Too many times, people simplify things and the devil is in the details.
This error is happening to me. MySQL query browser works, but in hibernate of 7 columns and only one column always came with all null fields. I checked all the ids and they were not null. The error was in the construction of SQL Native. I had to change the way of writing it. Ai worked.
SELECT c.idContratoEmprestimo as idContratoEmprestimo,c.dtOperacao as dataOperacao,p.cpf as cpf,p.nome as nome,(Select count(p2.idParcelaEmprestimo) from EMP_PARCELA p2 where p2.valorPago > 0 and p2.dtPagamento is not nulland p2.idContratoEmprestimo = c.idContratoEmprestimo and p2.mesCompetencia <= '2014-08-01') as parcelasPagas, c.numeroParcelas as numeroParcelas,pe.valorPago as valorParcelaFROM EMP_CONTRATO c inner join TB_PARTICIPANTE_DADOS_PLANO AS pp on pp.idParticipantePlano = c.idParticipantePlanoinner join TB_PARTICIPANTE as p on p.id = pp.idParticipanteinner join TB_PARTICIPANTE_INSTITUIDOR as pi on pi.PARTICIPANTE_ID = p.idinner join EMP_PARCELA as pe on pe.idContratoEmprestimo = c.idContratoEmprestimowhere c.dtInicioContrato <= '2014-08-01' and pi.INSTITUIDOR_ID = 1and c.avaliado is trueand pe.mesCompetencia = '2014-08-01'and c.deferido is trueand c.dtQuitacao is nulland c.dtExclusao is nulland pe.valorPago is not nullgroup by c.idContratoEmprestimoorder by p.nome