有人可以帮忙解决如何解决此错误:
java.lang.IllegalStateException: No aliases found in result tuple! Make sure your query defines aliases!
导致此错误的JPA查询是:
@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);
我在网上研究了这个错误,但很多问题似乎都没有提到对象的命名,但我认为自从使用sm
以来我没有这个问题。
感谢。
答案 0 :(得分:2)
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);