我的 .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/