我已将复合文件添加到 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));
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)