当前位置: 首页 > 知识库问答 >
问题:

java.lang.IllegalStateException:在结果元组中找不到别名

韩华美
2023-03-14

请帮助解决此错误:

@Query("SELECT sm.messageCode, sm.messageDescription FROM SystemMessage sm WHERE UPPER(sm.messageTypeCode) = TRIM(UPPER(:messageTypeCodeEntered))")
    public List<Map<String, String>> returnCodeToDescMapping(@Param("messageTypeCodeEntered") String messageTypeCodeEntered);

共有1个答案

狄彬彬
2023-03-14

Spring Data JPA只能返回SystemMessage,但您可以将@Query设置为:

@Query("SELECT sm FROM SystemMessage sm WHERE UPPER(sm.messageTypeCode) = TRIM(UPPER(:messageTypeCodeEntered))")
public List<SystemMessage> returnCodeToDescMapping(@Param("messageTypeCodeEntered") String messageTypeCodeEntered);

或作为

//Message is a new class with constructor public Message(messageCode, messageDescription ){..}
@Query("select new Message(sm.messageCode as messageCode , sm.messageDescription as messageDescription) from SystemMessage sm where UPPER(sm.messageTypeCode) = TRIM(UPPER(:messageTypeCodeEntered))")
public List<Message> returnCodeToDescMapping(@Param("messageTypeCodeEntered") String messageTypeCodeEntered);
 类似资料: