Now I have two classes
class A{
@Column(name="num1")
private BigDecimal num1;
private B b;
//getter and setter
}
And
class B{
@Column(name="num2")
private BigDecimal num2;
//getter and setter
}
I have tried to add a new field called total in class A and add the getter in AView.
class A{
@Column(name="num1")
private BigDecimal num1;
// a custom field that does not exist in db
private BigDecimal total;
//suppose we have joined two entity using @join annotation
private B b;
public getTotal(){
return this.num1.add(b.num2);
}
// other getter and setter
}
public interface AView{
// add num1 and num2
BigDecimal total();
}
But it showed error message.
I have found a solution but it does not work.
https://www.baeldung.com/spring-data-jpa-projections#2-open-projections
Are there any other solutions? Thank you!
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…