我在 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();