0

我是新来的冬眠。我用的是MYSQL数据库。我的表中有日期字段。它的类型是日期。有一个值 1989-08-13。当我使用休眠获得价值时,它给出的日期为 6189498000000。我想获得真实日期的价值(1989-08-13)。请帮我

这是我的 xml 文件

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<!-- Generated Aug 27, 2013 1:03:09 AM by Hibernate Tools 4.0.0 -->
<hibernate-mapping>
    <class name="core.classes.Staff" table="staff" catalog="surgercare">
        <id name="staffId" type="int">
            <column name="staff_ID" />
            <generator class="assigned" />
        </id>
        <property name="staffName" type="string">
            <column name="staff_Name" length="150" />
        </property>
        <property name="staffDesignation" type="string">
            <column name="staff_designation" length="50" />
        </property>
        <property name="createDate" type="timestamp">
            <column name="CreateDate" length="19" />
        </property>
        <property name="createUser" type="string">
            <column name="CreateUser" length="200" />
        </property>
        <property name="lastUpDate" type="timestamp">
            <column name="LastUpDate" length="19" />
        </property>
        <property name="lastUpDateUser" type="string">
            <column name="LastUpDateUser" length="200" />
        </property>
    </class>
</hibernate-mapping>

我的班级档案

import java.util.Date;

public class Staff implements java.io.Serializable {

    /**
     * 
     */
    private static final long serialVersionUID = 1L;
    private int staffId;
    private String staffName;
    private String staffDesignation;
    private Date createDate;
    private String createUser;
    private Date lastUpDate;
    private String lastUpDateUser;

    public Staff() {
    }

    public Staff(int staffId) {
        this.staffId = staffId;
    }

    public Staff(int staffId, String staffName, String staffDesignation,
            Date createDate, String createUser, Date lastUpDate,
            String lastUpDateUser) {
        this.staffId = staffId;
        this.staffName = staffName;
        this.staffDesignation = staffDesignation;
        this.createDate = createDate;
        this.createUser = createUser;
        this.lastUpDate = lastUpDate;
        this.lastUpDateUser = lastUpDateUser;
    }

    public int getStaffId() {
        return this.staffId;
    }

    public void setStaffId(int staffId) {
        this.staffId = staffId;
    }

    public String getStaffName() {
        return this.staffName;
    }

    public void setStaffName(String staffName) {
        this.staffName = staffName;
    }

    public String getStaffDesignation() {
        return this.staffDesignation;
    }

    public void setStaffDesignation(String staffDesignation) {
        this.staffDesignation = staffDesignation;
    }

    public Date getCreateDate() {
        return this.createDate;
    }

    public void setCreateDate(Date createDate) {
        this.createDate = createDate;
    }

    public String getCreateUser() {
        return this.createUser;
    }

    public void setCreateUser(String createUser) {
        this.createUser = createUser;
    }

    public Date getLastUpDate() {
        return this.lastUpDate;
    }

    public void setLastUpDate(Date lastUpDate) {
        this.lastUpDate = lastUpDate;
    }

    public String getLastUpDateUser() {
        return this.lastUpDateUser;
    }

    public void setLastUpDateUser(String lastUpDateUser) {
        this.lastUpDateUser = lastUpDateUser;
    }

}

这是我的控制器

tx = ses.beginTransaction();
Query query = ses.createQuery("select s from Staff as s where  s.staffId = :ID");
query.setString("ID", docID);
List<Staff> DocDetailsList = castlist(Staff.class,query.list());
tx.commit();
return DocDetailsList;
4

1 回答 1

1

在您的 hbm 文件中,有“时间戳”列类型。让hibernate猜测列类型:

<property name="createDate" column="CreateDate" />

换句话说,如果您具有以下属性:

java.util.Date createDate;

hibernate3-maven-plugin hibernate3:hbm2ddl 目标将在 MySql 中创建以下列:

`CreateDate` datetime DEFAULT NULL

注意:日期时间和时间戳有不同的范围。Java Long(时间戳)和 java.util.Date 也是如此。

于 2013-09-18T15:01:39.587 回答