Is there a way to map a calculated property using JPA?
Assuming I have an Invoice
object with one or more InvoiceLineItems
within it, I wan
I know that I am necro-ing this thread, but maybe it might help somebody out.
If you want to calculate the value on read, the @PostLoad
annotation might be what you want:
@Transient
private BigDecimal totalAmount;
@PostLoad
public void onPostLoad() {
BigDecimal amount = BigDecimal.ZERO;
for (InvoiceLineItem lineItem : lineItems) {
amount = amount.add(lineItem.getTotalAmount());
}
this.totalAmount = amount;
}