1

我在从表中获取正确数据时遇到问题。该类CompanyActualData包含该类的一个成员CompanyActualDataPK。该类CompanyActualDataPK包含该类的成员Entity和 String isinEntity有一个 String visibility,我想过滤它。我想得到所有CompanyActualData,有一个特别的visibility和一个特别的isin

目前,我在努力制定正确的标准。

List<CompanyActualData> l = 
    session.createCriteria(CompanyActualData.class)
    .add(Restrictions.eq("companyActualDataPK.isin", isin))
    .createCriteria("companyActualDataPK")
    .add(Restrictions.eq("companyActualDataPK.entity.visible", visibility))
    .list();

我总是得到错误

无法解析属性:de.ll.web.pm.services.company.actual.CompanyActualData 的 companyActualDataPK.entity.visible

也许有人有暗示。

<class name="de.ll.web.pm.services.company.actual.CompanyActualData" schema = "reporting"   table="company_actual">

        <composite-id name="companyActualDataPK" class="de.ll.web.pm.services.company.actual.CompanyActualDataPK">          
            <key-property name="isin" column="isin"/>
            <key-property name="countryId" column="country_id"/>
            <key-many-to-one  name="entity"     class="de.ll.web.pm.services.entity.Entity" lazy="false" >
                <column name="entity_id"></column> 
            </key-many-to-one> 
        </composite-id>

        <property name="sedol" column="sedol" not-null="false" />
        <property name="valueDouble" column="value_double" not-null="false" />
        <property name="valueString" column="value_string" not-null="false" />
        <property name="date" column="date_id" not-null="false" />

        <many-to-one name="currency"
            class="de.ll.web.pm.services.currency.Currency" lazy="false" insert="false" update="false">
            <column name="currency_id"></column>
        </many-to-one>  
    </class>

>

<class name="de.ll.web.pm.services.entity.Entity"
        table="md_entity" schema="reporting">

        <id name="entityId" column="entity_id" type="java.lang.String">
            <generator class="native" />
        </id>

        <property name="name" column="name" />
        <property name="description" column="description" />
        <property name="vendor" column="vendor" />
        <property name="visible" column="is_visible" type="java.lang.String"  />
        <property name="currency" column="is_currency" type="java.lang.String" />
</class>
4

1 回答 1

1

通过这样做createCriteria("companyActualDataPK")Criteria扎根于PK类。以下 s 中给出的所有属性名称Restriction都将与CompanyActualDataPK类相关。

尝试做:

List<CompanyActualData> l = 
    session.createCriteria(CompanyActualData.class)
    .add(Restrictions.eq("companyActualDataPK.isin", isin))
    .add(Restrictions.eq("companyActualDataPK.entity.visible", visibility))
    .list();
于 2012-06-19T16:51:02.207 回答