Hello,
See code snippet below for reference.
I have a 1:m relationship between Project and Capex. I have a @Formula computed property in my Project that adds up the total amount values of the Capex entities related to the Project. It works and computes the right total except when I add/delete/modify a Capex the old computed total is sometimes still maintained in Project.
How can I force Hibernate to throw away the computed value (totalCE) and re-run the @Formula SQL?
I'm using Seam and EntityManager, rather than raw Hibernate.
Code:
@Entity
@Table(name = "project", catalog = "spurs")
public class Project implements java.io.Serializable {
private long projectId;
private Integer version;
private Integer totalCE;
@Id @GeneratedValue
@Column(name = "projectID", unique = true, nullable = false)
@NotNull
public long getProjectId() {
return this.projectId;
}
public void setProjectId(long projectId) {
this.projectId = projectId;
}
@Version
@Column(name = "version")
public Integer getVersion() {
return this.version;
}
@Formula("(select sum(c.amount) from Capex c where c.projectID = projectID)")
public Integer getTotalCapex() {
return totalCE;
}
public void setTotalCapex( Integer totalCE ) {
this.totalCE = totalCE;
}
}
Thanks for any hints,
Greg