gpt4 book ai didi

java - Hibernate 在一对多映射上添加 where 子句

转载 作者:搜寻专家 更新时间:2023-10-30 20:10:40 25 4
gpt4 key购买 nike

我的 .hbm 文件中有这个设置。

<set name="subTopicsTb" table="subtopics_tb" inverse="true" lazy="false" fetch="select">
<key>
<column name="topic_id" />
</key>
<one-to-many class="com.topics.model.SubTopics" />
</set>

现在,默认情况下,hibernate 获取所有子主题,其中 topic_id 是 id。我想过滤子主题。添加类似 where subTopics.date is not null 谢谢

最佳答案

这确实有效,因为 date 是您数据库中的列名。 set 中的 where 属性 appends raw sql 到你的查询,所以你必须指定它在你的数据库中并且 NOT HQL :

<set name="subTopicsTb" table="subtopics_tb" inverse="true" lazy="false" 
fetch="select" where="date is not null">
<key>
<column name="topic_id" />
</key>
<one-to-many class="com.topics.model.SubTopics" />
</set>

关于java - Hibernate 在一对多映射上添加 where 子句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14565241/

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