复合键的 Hibernate 标准问题

发布于 2024-11-09 17:34:03 字数 1542 浏览 0 评论 0原文

我得到了这个休眠映射:

<class name="CoverageTerm" table="coverage_term">

    <composite-id name="id" class="CoverageTermPK">
        <key-many-to-one name="productTerm" class="ProductTerm">
            <column name="termtype_id"></column>
            <column name="product_id" ></column>
        </key-many-to-one>
        <key-many-to-one name="productCoverage" class="ProductCoverage" column="product_coverage_id"></key-many-to-one>
    </composite-id>

    <property name="data"/>
</class>

这是一个简单的复合键映射,具有与表productCoverage 的关系和与productterm 的复合键关系。

现在问题出现在我的搜索功能中:

public CoverageTerm getCoverageTermFromProductTermCoverage(ProductTerm productTerm, ProductCoverage productCoverage) {
    Criteria critCt = getSession().createCriteria(CoverageTerm.class);
    Criteria critCtId = critCt.createCriteria("id");
    critCtId.add(Restrictions.eq("productTerm", productTerm));
    critCtId.add(Restrictions.eq("productCoverage", productCoverage));
    return (CoverageTerm) critCt.uniqueResult();
}

这应该让我在“id”(这是主键,CoverageTermPK)上创建一个子标准并对其添加限制,但是当我运行它时,我收到错误消息:

org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.hibernate.QueryException: could not resolve property: productTerm of: CoverageTerm

这感觉很奇怪,它不应该在那里得到 CoverageTermPK 吗?如果我尝试在“data”属性上使用子标准,则标准有效,但我似乎无法获得“id”子标准上的 PK。

关于为什么会发生这种情况有什么想法吗?

I got this hibernate mapping:

<class name="CoverageTerm" table="coverage_term">

    <composite-id name="id" class="CoverageTermPK">
        <key-many-to-one name="productTerm" class="ProductTerm">
            <column name="termtype_id"></column>
            <column name="product_id" ></column>
        </key-many-to-one>
        <key-many-to-one name="productCoverage" class="ProductCoverage" column="product_coverage_id"></key-many-to-one>
    </composite-id>

    <property name="data"/>
</class>

This is a simple composite key mapping with a relation to table productCoverage and a composite key relation to productterm.

Now the problem comes in my search function:

public CoverageTerm getCoverageTermFromProductTermCoverage(ProductTerm productTerm, ProductCoverage productCoverage) {
    Criteria critCt = getSession().createCriteria(CoverageTerm.class);
    Criteria critCtId = critCt.createCriteria("id");
    critCtId.add(Restrictions.eq("productTerm", productTerm));
    critCtId.add(Restrictions.eq("productCoverage", productCoverage));
    return (CoverageTerm) critCt.uniqueResult();
}

This should let me make a subcriteria on "id" (which is the primary key, CoverageTermPK) and add restrictions on it, but when I run it I get the error message:

org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.hibernate.QueryException: could not resolve property: productTerm of: CoverageTerm

This feels strange, shouldn't it get the CoverageTermPK there? If I try with a subcriteria on the "data" property the criterias work, I just don't seem to be able to get the PK on the "id" subcriteria.

Any ideas as to why this is happening?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

止于盛夏 2024-11-16 17:34:03

不确定您的具体类结构,但尝试以这种方式添加 id 而不是单独的标准:

Restrictions.eq("id.productTerm", productTerm);
Restrictions.eq("id.productCoverage", productCoverage);

Not sure about your specific class structure but try to add id this way instead of separate criteria:

Restrictions.eq("id.productTerm", productTerm);
Restrictions.eq("id.productCoverage", productCoverage);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文