Spring JPA with native query and data projection mapping the wrong columns into the projected interface

前端 未结 3 2014
夕颜
夕颜 2021-02-13 16:16

I\'ve got a bit of a bizarre problem that I can\'t figure out why it\'s happening. I\'m sure I did something wrong, because this is my first time using a data projection and I\'

3条回答
  •  长发绾君心
    2021-02-13 16:57

    I had the same problem and i solved by odering the query columns alphabetically.

    In you case:

    public interface OrderTrackingRepository extends JpaRepository {
      @Query( nativeQuery = true,
              value = "SELECT a.accountnumber, o.date_of_order, t.tracking_id " +
                      "FROM account as a " +
                      "INNER JOIN orders as o USING (account_id) " +
                      "INNER JOIN tracking as t USING (tracking_id) " +
                      "WHERE a.accountnumber = :acctnum")
       Collection findOrderInfoForAccount(@Param("acctnum") acctNumber, Class type);
    }
    

    So you will get:

    getAccountNumber() -> accountnumber getDateOfOrder() -> date_of_order getTrackingId() -> tracking_id

提交回复
热议问题