跨实体的全局过滤

时间:2015-01-13 20:01:04

标签: hibernate orm coldfusion coldfusion-10

我的所有实体都包含isDeleted属性,因为我们已经实现了"软删除"我们所有的数据。我希望将全局过滤器应用于实体,这样无论它如何被调用,记录为isDelete = 0的记录都是唯一返回的记录。

我的商业实体的一个例子:

component persistent="true" table="hier_Businesses" extends="models.BaseEntity" {
    property name="businessID" fieldType="id" generator="increment";
    property name="business" notnull="true";
    property name="businessName" notnull="true";
    property name="isDeleted" ormtype="boolean" default="false";
    property name="businessDisplay" formula="concat(business, ' - ', businessName)";
    property name="centers" singularname="center" fieldtype="one-to-many" cfc="Center" fkcolumn="businessID" inverse="true" where="isDeleted = 0";

    // validation constraints
    this.constraints = {
        business = {validation = "required,max_length[5]", label = "Business"},
        businessName = {validation = "required,max_length[150]", label = "Business Name"}
    };

    public string function getFullBusinessName() {
        return getValue('businessName', '') & ' (' & getValue('business', '') & ')';
    }
}

如您所见,在centers属性上有where="isDeleted = 0",因此在调用Business.getCenters()时,只返回活动项。这适用于调用getCenters()的情况(请参阅conditions for accessors in Coldfusion ORM)。但是,如果使用HQL查询(例如使用 ORMExecuteQuery ),我将需要将这些条件重新应用于连接。

我还查看了使用ORMGetSession().createFilter(...)的示例,但是实现并不会在实体上创建全局过滤器。一些文档显示了修改Hibernate映射XML文件,但这是我无法访问的资源。

关于如何获得这方面的任何其他建议?

0 个答案:

没有答案