大家好,目前有個需求就是求表中兩列的和,然后將結(jié)果排序。詳細描述如下:
我的表里有兩列是費用a(pay_a)和費用b(pay_b),目前的需求是要將這兩者相加求和(select (pay_a + pay_b)from paytable),然后結(jié)果排序(數(shù)據(jù)庫使用的是oracle)。
我使用的框架是spring data jpa。在使用sort時,發(fā)現(xiàn)sort無法解析相加的表達式。提示表中無此成員。
換了個方法,在entity中用@Transient聲明一個新成員payall(數(shù)據(jù)庫表中無此列),定義getPayall()
{
return pay_a + pay_b;
}
然后在sort中,使用”payall“進行排序,結(jié)果運行錯誤,會提示
Unable to locate Attribute with the the given name [payall] on this ManagedType [io.koala.tobacco.dataservice.entity.PotentialCust]
目前有點不知道要如何處理了。還請各位高手多幫忙!感謝感謝!
@Query(value = "select new test.Account(a.price1 + a.price2) from Account a", nativeQuery = true)
Account testSum();
package test;
public class Account {
public Account(price1, price2) {
}
}
nativeQuery = true 使用原生的sql進行查詢