1

我有两张桌子

1) test_prefixmaster(CARDNO(Primary key),Name,Department)

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;
        }

    }
4

1 回答 1

1

交易映射

<?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>
于 2012-12-28T06:48:54.507 回答