-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Forcing @Formula field to recalculate
PostPosted: Wed Mar 21, 2007 2:27 pm 
Newbie

Joined: Thu Jan 11, 2007 7:38 pm
Posts: 4
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


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 22, 2007 11:19 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
session.refresh(object);

_________________
Emmanuel


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.