gpt4 book ai didi

java - hibernate : how to get records from composite key using Criteria Query

转载 作者:行者123 更新时间:2023-11-30 07:14:08 25 4
gpt4 key购买 nike

我在 hbm 文件中添加了复合文件,如下所示

<hibernate-mapping>
<class name="EmployeeSignin" table="EMPLOYEE_SIGNIN">
<composite-id name="id" class="EmployeeSigninId">
<key-property name="empId" type="string">
<column name="EMP_ID" length="10" />
</key-property>
<key-property name="signinDate" type="date">
<column name="SIGNIN_DATE" length="7" />
</key-property>
</composite-id>
</class>
</hibernate-mapping>

现在我要查询如下

select * from EmployeeSignin where emp_id='12345' and signin_date > 'some initial date' and signin_date<= 'some last date'

我不知道如何实现相同的目标,因为有一个引用 EmployeeSignId 的复合键。在这种情况下我如何创建条件查询?

我在下面尝试但得到 0 条记录

Criteria empAttendanceCr=session2.createCriteria(EmployeeSigninId.class);
Criterion attdDateCondition = Restrictions.conjunction()
.add(Restrictions.eq("empId", user.getEmpId()))
.add(Restrictions.le("signinDate", lastDate))
.add(Restrictions.ge("signinDate", startDate));

List empAttendanceList=empAttendanceCr
.add(attdDateCondition).list();

最佳答案

问题已解决。

我在下面试过哪个有效

Criteria empAttendanceCr=session2.createCriteria(EmployeeSignin.class);
//EmployeeSigninId empId=new EmployeeSigninId(user.getEmpId().toString());

Criterion attdDateCondition = Restrictions.conjunction()
.add(Restrictions.eq("id.empId",user.getEmpId().toString()))
.add(Restrictions.le("id.signinDate", lastDate))
.add(Restrictions.ge("id.signinDate", startDate));

关于java - hibernate : how to get records from composite key using Criteria Query,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18633941/

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