Hibernate @Formula

 hibernate 配置文件中写法:

<id name="reimId" type="java.lang.Integer">
            <column name="ReimId" />
            <generator class="native" />
        </id>

<property name="usedAmount" 
        formula="( select isnull(sum(f.amount*f.rate),0) from reimfact f where f.state != -1 and f.reimId = reimId)"/>

 类中的属性

public class ReimBudget extends com.nstc.dnaf.model.DNAFModel implements java.io.Serializable {
  

     /**
	 * 
	 */
	private static final long serialVersionUID = 6773815037408697643L;
	private Integer reimId;
     private Amcode amcode;
     private Integer month;
     private Double amount0;
     private Double amountX;
     private Short state;
     private Date createTime;
     private Integer creator;
     private Integer checker;
     private Date checkTime;
     private Double usedAmount;

 

 结合一篇文章:

 http://solonote.iteye.com/blog/215093

 

就会理解透彻。

 

你可能感兴趣的:(Hibernate)