programing

실행된 SQL이 값을 반환하더라도 최대 절전 모드가 null 목록을 반환합니다.

sourcejob 2023. 10. 11. 20:40
반응형

실행된 SQL이 값을 반환하더라도 최대 절전 모드가 null 목록을 반환합니다.

동면을 OR Mapper로 사용하고 있습니다.실제로는 좀 더 간단한 hql 쿼리를 실행하고 싶습니다.

SELECT a 
FROM Foo a 
WHERE a.status = :A0status 
ORDER BY a.bookingTypeCode ASC, 
         a.priority ASC

그런 다음 이 hql 쿼리는 다음과 같은 형태의 sql 쿼리로 변환됩니다.

select a.* 
from Foo a 
where a.status='A' 
order by a.bookingtypecode ASC, 
         a.priority ASC

Oracle SQL Developer를 사용하여 Oracle 데이터베이스에서 sql을 실행하면 17개의 행이 반환됩니다.그러나 hql 쿼리를 실행할 때(a의 list method를 사용하여Query전 17개의 요소들의 리스트를 얻었어요.null. 요소 개수는 맞지만 실제로 로드된 요소는 단 하나도 없습니다.

이렇게 쿼리를 만들고 실행할 수 있습니다.

// the hql query is stored in the hqlQuery variable;
// the parameter are stored in a Map<String, Object> called params
Query hQuery = hibSession.createQuery(hqlQuery);
for (Entry<String, Object> param : params.entrySet()) {
    String key = param.getKey();
    Object value = param.getValue();
    hQuery.setParameter(key, value);
}

List<?> result = hQuery.list();

The result I'm getting after executing query.list();

여기 뭐가 문제인지 아는 사람?

업데이트 1

최근에 동면 3.2에서 4.3.5로 업그레이드했습니다.업그레이드 전에는 모든 것이 정상적으로 작동했습니다.업그레이드 후 이 오류가 발생합니다.

동면의 로그 레벨을 TRACE로 설정하여 문제를 발견했습니다.실제로는 매핑/논리/데이터베이스 오류였습니다.기본 키는 엔티티 클래스에 따라 두 개의 열로 구성되어 있으며 이 열 중 하나는 null일 수 있습니다.그러나 기본 키는 결코 null이 될 수 없습니다.따라서 최대 절전 모드는 항상 null로 반환됩니다.

사용자 지정(및 버그) Result Transformer를 설정하지 않았다면, 두 번째로 좋은 추측은 디버거가 거짓말을 하고 있다는 것입니다.코드가 실제로 null 목록을 받습니까?

또한 당신이 보여주고 있는 코드를 가지고 테스트를 해야 합니다.너무 많은 경우, 사람들은 일을 단순화하고 악마는 세부사항에 있습니다.

이 오류는 저에게 일어나고 있습니다.MySQL 쿼리 브라우저는 작동하지만 7열의 최대 절전 모드에서는 항상 하나의 열만 모든 null 필드와 함께 제공됩니다.모든 ID를 확인해보니 null이 아니었습니다.SQL Native를 작성하는 중 오류가 발생했습니다.쓰는 방법을 바꿔야 했습니다.인공지능이 통했습니다.

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 null
and p2.idContratoEmprestimo = c.idContratoEmprestimo and p2.mesCompetencia <= '2014-08-01') as parcelasPagas, c.numeroParcelas as numeroParcelas,
pe.valorPago as valorParcela
FROM EMP_CONTRATO c inner join TB_PARTICIPANTE_DADOS_PLANO AS pp on pp.idParticipantePlano = c.idParticipantePlano
inner join TB_PARTICIPANTE as p on p.id = pp.idParticipante
inner join TB_PARTICIPANTE_INSTITUIDOR as pi on pi.PARTICIPANTE_ID = p.id
inner join EMP_PARCELA as pe on pe.idContratoEmprestimo = c.idContratoEmprestimo
where c.dtInicioContrato <= '2014-08-01' and pi.INSTITUIDOR_ID = 1
and c.avaliado is true
and pe.mesCompetencia = '2014-08-01'
and c.deferido is true
and c.dtQuitacao is null
and c.dtExclusao is null
and pe.valorPago is not null
group by c.idContratoEmprestimo
order by p.nome

언급URL : https://stackoverflow.com/questions/24657919/hibernate-returns-list-of-nulls-although-executed-sql-returns-values

반응형