gpt4 book ai didi

java - 如何创建 Hibernate Pojo 和 hbm 文件

转载 作者:太空宇宙 更新时间:2023-11-04 07:53:11 26 4
gpt4 key购买 nike

我有两张 table

1) test_prefixmaster(CARDNO(主键),姓名,部门)

2)test_prefixtransactions(CARDNO(FK),当前日期)

我想使用 Spring 和 Hibernate 开发两个给定日期范围内的员工缺勤报告

任何人都可以如何在没有注释的情况下使用 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>

关于java - 如何创建 Hibernate Pojo 和 hbm 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14065460/

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