我有两张桌子
1)test_prefixmaster(CARDNO(主键),名称,部门)
2)test_prefixtransactions(CARDNO(FK),PresentDate)
我想使用Spring和Hibernate开发两个给定日期范围之间的员工缺席报告
请问有人可以在没有注解的情况下将其与休眠模式对应吗?
我的查询以产生员工缺席结果:
SELECT m.CARDNO AS `EmpCode`
, m.NAME AS `EmpName`
, m.DEPARTMENT AS `Department`
, d.dt AS `AbsentDate`
FROM ( SELECT DATE(t.S_DateTime) AS dt
FROM test_prefixtransactions t
WHERE t.S_DateTime >= '2012-11-26'
AND t.S_DateTime < DATE_ADD( '2012-11-26' ,INTERVAL 1 DAY)
GROUP BY DATE(t.S_DateTime)
ORDER BY DATE(t.S_DateTime)
) d
CROSS
JOIN test_prefixmaster m
LEFT
JOIN test_prefixtransactions p
ON p.S_DateTime >= d.dt
AND p.S_DateTime < d.dt + INTERVAL 1 DAY
AND p.CARDNO = m.CARDNO
WHERE p.CARDNO IS NULL
ORDER
BY m.CARDNO
, d.dt;
Note:'d' is The inline view aliased as d gets us a set of "date" values that we are checking. Using the transaction table as a source of these "date" values is a convenient way to do this. Basically, what we are after is a distinct set of DATE values between the two values passed in as arguments
Note:If an Employee is absent, then no record will be inserted into the Transaction table
我采取了这样的Pojo:
public class Transcations {
private String cardno;
public String getCardno() {
return cardno;
}
public void setCardno(String cardno) {
this.cardno = cardno;
}
}
package Employee.model;
import java.io.Serializable;
public class PrefixMaster implements Serializable {
private static final long serialVersionUID = -5527566248002296042L;
private String empname;
private String empcode;
private String department;
public String getEmpname() {
return empname;
}
public void setEmpname(String empname) {
this.empname = empname;
}
public String getEmpcode() {
return empcode;
}
public void setEmpcode(String empcode) {
this.empcode = empcode;
}
public String getDepartment() {
return department;
}
public void setDepartment(String department) {
this.department = department;
}
}
最佳答案
交易映射
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="Employee.model.Transcations "
table="transaction_master">
<id name="id" column="id">
<generator class="native"></generator>
</id>
<property name="cardno" type="string" column="card_no" />
</hibernate-mapping>
映射PrefixMaster
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="Employee.model.PrefixMaster "
table="prefix_master">
<id name="id" column="id">
<generator class="native"></generator>
</id>
<property name="empname" type="string" column="emp_name" />
<property name="empcode" type="string" column="emp_code" />
<property name="department" type="string" column="dept_name" />
</hibernate-mapping>