Hi,
We would like to use @Embeddable classes in our beans. Is there any way to apply constraints to @Embedded objects?
We have tried doing it in the next example, modifying a little your Customer and CustomerLogic classes and adding an @Embeddable class Balance.
But we get this exception "java.lang.RuntimeException: Logic method constraintCreditLimit for buslogicdemo.data.Customer has expression (balance.amount <= creditLimit) which refers to relationship balance, which does not seem to exist."
:::java
@Entity
@Table(name="customer")
public class Customer implements java.io.Serializable {
@Id
@Column(name="name", unique=true, nullable=false)
public String getName() { return name; }
public void setName(String name) { this.name = name; }
private String name;
@Embedded public Balance getBalance() { return balance; } public void setBalance(Balance balance) { this.balance = balance; } private Balance balance; @Column(name="credit_limit") public Double getCreditLimit() { return this.creditLimit; } public void setCreditLimit(Double creditLimit) { this.creditLimit = creditLimit; } private Double creditLimit; @OneToMany(cascade={CascadeType.ALL}, fetch=FetchType.LAZY, mappedBy="customer") @OrderBy("orderNumber desc") public List<Purchaseorder> getPurchaseorders() { return this.purchaseorders; } public void setPurchaseorders(List<Purchaseorder> purchaseorders) { this.purchaseorders = purchaseorders; } private List<Purchaseorder> purchaseorders = new Vector<Purchaseorder>();
}
@Embeddable
public class Balance implements java.io.Serializable {
@Column(name="balance")
public Double getAmount() { return amount; }
public void setAmount(Double amount) { this.amount = amount; }
private Double amount;
}
public class CustomerLogic extends LogicObject {
@CurrentBean
protected Customer customer;
@Constraint(value = "balance.amount <= creditLimit", errorMessage = "Customer {name} has a balance of ${balance.amount} which exceeds the credit limit of ${creditLimit}" ) public void constraintCreditLimit() { }
}
Regards,
Sira
Anonymous
Partial support provided in ABL 2.1.7 - you should no longer get exceptions when such attributes are defined. We are investigating support for enabling such attributes to be used in logic.