java - 如何限制我的域对象中的集合
问题描述
该代码使用(旧式)休眠检索对象:
Session session = super.getSession();
Student results = (Student) session.get(Student.class, id);
Student 对象在其中包含一组孩子的成就。
<hibernate-mapping>
<class name="edu.texas.Student" table="STUDENT" >
<property name="createUser" type="string">
<column name="CREATE_USER" length="25" />
</property>
<set name="achievements" inverse="true" lazy="true" table="ACHIEVEMENTS" fetch="select">
<key>
<column name="ACHIEVEMENT_ID" length="25" not-null="true" />
</key>
<one-to-many class="edu.texas.Achievements" />
</set>
我希望成就集受到日期范围的限制(例如,仅限于今年的成就,而不是孩子的整个职业生涯)。
我开始对 Set 的对象使用标准,但标准想要返回一个列表。
在这种情况下,该列表位于我的 Student 对象内。
Criteria criteria = session.createCriteria(Student.class)
.createAlias("achievements", "a")
.add( Restrictions.between("a.createTs", startDate, endDate ) );
results = (Student) crit.uniqueResult();
解决方案
推荐阅读
- c# - 实体框架核心 2.1 将 AsNoTracking 与多个异步一起使用会给出 InvalidOperationException:连接未关闭
- c++ - 使用 glDrawArraysInstanced 渲染 OpenGL tilemap 的问题
- javascript - 在这种情况下我需要 redux-promise 吗?
- api - 我们如何让依赖慢的 API 更快?
- javascript - 将值分配给另一个具有动态分配键的对象内的对象
- java - 春季启动 + REST + HATEOAS + HAL
- kotlin - 防止 String.Contains 匹配空
- ms-access - 防止 MS Access 查询中的 MS Word 邮件合并锁定文件
- asynchronous - Jersey 异步客户端处理程序在服务器重新启动后永远不会超时
- raspberry-pi - 使用外围设备和内存映射在 QEMU 中模拟 Raspberry Pi 1 或 0