How to sort results of sum of two columns using spring data jpa
过去多啦不再A梦
过去多啦不再A梦 2017-05-27 17:41:27
0
1
1085

Hello everyone, there is currently a need to find the sum of two columns in the table, and then sort the results. The detailed description is as follows:
There are two columns in my table: fee a (pay_a) and fee b (pay_b). The current requirement is to add the two and sum them (select (pay_a pay_b) from paytable), Then the results are sorted (the database uses oracle).

The framework I use is spring data jpa. When using sort, I found that sort cannot parse the addition expression. There is no such member in the prompt table.
Change the method, use @Transient to declare a new member payall in the entity (there is no such column in the database table), and define getPayall()
{

return pay_a + pay_b;

}
Then in sort, use "payall" to sort, and the result is an error.
Unable to locate Attribute with the given name [payall] on this ManagedType [io.koala.tobacco. dataservice.entity.PotentialCust]

I don’t know how to deal with it now. Please help all the experts! Thank you!

过去多啦不再A梦
过去多啦不再A梦

reply all(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 Use native sql to query

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template