gpt4 book ai didi

java - Hibernate 键多对一

转载 作者:太空宇宙 更新时间:2023-11-04 08:11:41 26 4
gpt4 key购买 nike

我在从表中获取正确的数据时遇到问题。 CompanyActualData 类包含 CompanyActualDataPK 类的成员。 CompanyActualDataPK 类包含 Entity 类的成员和字符串 isinEntity 有一个字符串 visibility,我想对其进行过滤。我想获取所有具有特殊可见性和特殊isinCompanyActualData

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

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

我总是收到错误

could not resolve property: companyActualDataPK.entity.visible of: de.ll.web.pm.services.company.actual.CompanyActualData

也许有人有提示。

<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>

最佳答案

通过执行 createCriteria("companyActualDataPK")Criteria Root 于 PK 类。以下 Restriction 中给出的所有属性名称都将相对于 CompanyActualDataPK 类。

尝试这样做:

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

关于java - Hibernate 键多对一,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11105500/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com