Oracle中Timestamp使用

建表语句如下:

create table L_LOG_RECORD
(
LOG_ID number(6) not null primary key,
LOG_USER varchar2(50) not null,
LOG_OPERATION varchar(50) not null,
LOG_OBJECT varchar2(100) not null,
LOG_TIME date not null
);

怎奈,通过Hibernate逆向工程后,生成的实体:

package com.idealing.model;

import java.sql.Timestamp;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

/**
 * LLogRecord entity. @author MyEclipse Persistence Tools
 */
@Entity
@Table(name = "L_LOG_RECORD", schema = "IDEALING")
public class LLogRecord implements java.io.Serializable {

    // Fields

    /**
     * 
     */
    private static final long serialVersionUID = 1L;
    private Integer logId;
    private String logUser;
    private String logOperation;
    private String logObject;
    private Timestamp logTime;

    // Constructors

    /** default constructor */
    public LLogRecord() {
    }

    /** full constructor */
    public LLogRecord(Integer logId, String logUser, String logOperation,
            String logObject, Timestamp logTime) {
        this.logId = logId;
        this.logUser = logUser;
        this.logOperation = logOperation;
        this.logObject = logObject;
        this.logTime = logTime;
    }

    // Property accessors
    @Id
    @SequenceGenerator(name = "LOG_SEQ",sequenceName = "LOG_SEQ",allocationSize = 1)
    @GeneratedValue(strategy = GenerationType.SEQUENCE,generator = "LOG_SEQ")
    @Column(name = "LOG_ID", unique = true, nullable = false, precision = 6, scale = 0)
    public Integer getLogId() {
        return this.logId;
    }

    public void setLogId(Integer logId) {
        this.logId = logId;
    }

    @Column(name = "LOG_USER", nullable = false, length = 50)
    public String getLogUser() {
        return this.logUser;
    }

    public void setLogUser(String logUser) {
        this.logUser = logUser;
    }

    @Column(name = "LOG_OPERATION", nullable = false, length = 50)
    public String getLogOperation() {
        return this.logOperation;
    }

    public void setLogOperation(String logOperation) {
        this.logOperation = logOperation;
    }

    @Column(name = "LOG_OBJECT", nullable = false, length = 100)
    public String getLogObject() {
        return this.logObject;
    }

    public void setLogObject(String logObject) {
        this.logObject = logObject;
    }

    @Column(name = "LOG_TIME", nullable = false, length = 7)
    public Timestamp getLogTime() {
        return this.logTime;
    }

    public void setLogTime(Timestamp logTime) {
        this.logTime = logTime;
    }

}

date成了Timestamp,不明白。。。。

在进行日志查询的时候,前台给的日期格式是yy-mm-dd,而Timestamp的格式还包括了时分秒及.后的9位小数。无奈,就开始拼凑字符串,前台的date=+" 00:00:00.0",空格是必须的,不然老是提示格式错误。但是按照此方法,还是提示错误,尝试了一下,date+=" 00:00:00",对了!但是,明明数据库里面的时间是有小数的,对此不明白。。。

 String queryString = "from LLogRecord as m where m.logUser ='"+logUser+"' and m.logTime >=to_date('"+date1+"','YYYY-MM-DD HH24:MI:SS') and m.logTi  me <=to_date('"+date2+"','YYYY-MM-DD HH24:MI:SS')";
 List<LLogRecord> logs= getHibernateTemplate().find(queryString);

date1和date2即是上述拼出的字符串。这样就可以查询Timestamp类型了。

posted @ 2013-06-13 23:01  idealing  阅读(4080)  评论(1编辑  收藏  举报