java - 如何使用spring data jpa进行两个列和的结果排序
问题描述
大家好,目前有个需求就是求表中两列的和,然后将结果排序。详细描述如下:我的表里有两列是费用a(pay_a)和费用b(pay_b),目前的需求是要将这两者相加求和(select (pay_a + pay_b)from paytable),然后结果排序(数据库使用的是oracle)。
我使用的框架是spring data jpa。在使用sort时,发现sort无法解析相加的表达式。提示表中无此成员。换了个方法,在entity中用@Transient声明一个新成员payall(数据库表中无此列),定义getPayall(){
return pay_a + pay_b;
}然后在sort中,使用”payall“进行排序,结果运行错误,会提示 Unable to locate Attribute with the the given name [payall] on this ManagedType [io.koala.tobacco.dataservice.entity.PotentialCust]
目前有点不知道要如何处理了。还请各位高手多帮忙!感谢感谢!
问题解答
回答1:@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进行查询
相关文章:
1. docker网络端口映射,没有方便点的操作方法么?2. docker容器呢SSH为什么连不通呢?3. mac连接阿里云docker集群,已经卡了2天了,求问?4. debian - docker依赖的aufs-tools源码哪里可以找到啊?5. vim - docker中新的ubuntu12.04镜像,运行vi提示,找不到命名.6. docker gitlab 如何git clone?7. docker安装后出现Cannot connect to the Docker daemon.8. 为什么我ping不通我的docker容器呢???9. golang - 用IDE看docker源码时的小问题10. docker-compose 为何找不到配置文件?

网公网安备