在我的 OpenXava 应用程序中,@Calculation 注释不起作用。
这是我为使用@Calculation 的@Embeddable 编写的代码:
import java.math.*;
import java.time.*;
import javax.persistence.*;
import org.openxava.annotations.*;
import lombok.*;
@Getter @Setter
@Embeddable
public class Payment {
@ManyToOne(fetch=FetchType.EAGER)
@DescriptionsList
Paymentfrequency paymentFrequency;
LocalDate firstPaymentDate;
@Stereotype("MONEY")
BigDecimal paymentAmount;
@ManyToOne(fetch=FetchType.LAZY)
@DescriptionsList
Methodofpayment methodOfPayment;
@ReadOnly
@Stereotype("MONEY")
@Calculation("paymentAmount * paymentFrequency.frequencyPerYear")
BigDecimal annualContribution;
}
这是具有可嵌入集合的实体的代码:
import javax.persistence.*;
import lombok.*;
@Entity @Getter @Setter
public class Paymentfrequency extends GenericType {
int frequencyPerYear;
// Payment is used as collection
@ElementCollection
@ListProperties("firstPaymentDate, paymentAmount, paymentFrequency,
methodOfPayment, annualContribution")
Collection<Payment> payments;
}
结果如下:
请注意,当操作数更改时,不会重新计算最后一列(annualContribution)。
为什么在这种情况下@Calculation 不起作用?