求助:hibernate取date日期问题(实际得到前一天),使用的是myeclipse5.5生成po
9441 2008-07-31 11:16:36 目前在做工程中,页面存入日期(精确到天),sybase中使用sybase自身工具查看值无误,使用hibernate 3 获取后得到timestamp型数据值为前一天的23:59:59 997, 格式化后就变成前一天了。
如例:页面存入 2008-07-06 页面读取就成了2008-07-05.
使用hibernate获取的po中为2008-07-05 23:59:58 997
po是使用myeclipse5.5自动生成的,数据库中数据类型为date,po中数据类型为java.util.date.
工程使用了hibernate-spring-struts-sybase.
因为其他原因使用的是jtds1.2的sybase驱动。
我跟踪了代码的执行不知道为什么会这样(没有跟踪hibernate内部),在google搜索也没有找到相关问题。
是否是我缺少了一些配置?除了直接在代码中修正错误,还有别的办法么?
代码太长,多余的删掉了
po代码:
package cn.com.cssnj.ntsh.po;
import java.util.Date;
/**
* TFpHyyzkprdb generated by MyEclipse Persistence Tools
*/
public class TFpHyyzkprdb implements java.io.Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
// Fields
private Date yyzhfzrq;
private Date swdjzrq;
// Constructors
/** default constructor */
public TFpHyyzkprdb() {
}
/** minimal constructor */
public TFpHyyzkprdb(String gzlh) {
this.gzlh = gzlh;
}
/** full constructor */
public TFpHyyzkprdb(String gzlh, String wjdm, String nsrsbh, String jjxz,
String bsrmc, String frmc, String frsfzh, String lxdh, String yhzh,
String khyh, String idKhyh, String yyzzhm, Date yyzhfzrq,
Date swdjzrq, String swdjzhm, String dlysjyxkzh, String slysjyxkzh,
Double ntghylwje, String zbysgj, String zyhzybgdzjzq,
String zbszzlmc, Integer snfpsyl, String nsrsqyj, String jbr,
String fzr, Date sqrq, String submitFlag, Date lrsj, String nsrmc) {
this.gzlh = gzlh;
this.wjdm = wjdm;
this.nsrsbh = nsrsbh;
this.jjxz = jjxz;
this.bsrmc = bsrmc;
this.frmc = frmc;
this.frsfzh = frsfzh;
this.lxdh = lxdh;
this.yhzh = yhzh;
this.khyh = khyh;
this.idKhyh = idKhyh;
this.yyzzhm = yyzzhm;
this.yyzhfzrq = yyzhfzrq;
this.swdjzrq = swdjzrq;
this.swdjzhm = swdjzhm;
this.dlysjyxkzh = dlysjyxkzh;
this.slysjyxkzh = slysjyxkzh;
this.ntghylwje = ntghylwje;
this.zbysgj = zbysgj;
this.zyhzybgdzjzq = zyhzybgdzjzq;
this.zbszzlmc = zbszzlmc;
this.snfpsyl = snfpsyl;
this.nsrsqyj = nsrsqyj;
this.jbr = jbr;
this.fzr = fzr;
this.sqrq = sqrq;
this.submitFlag = submitFlag;
this.lrsj = lrsj;
this.nsrmc = nsrmc;
}
// Property accessors
public Date getYyzhfzrq() {
return this.yyzhfzrq;
}
public void setYyzhfzrq(Date yyzhfzrq) {
this.yyzhfzrq = yyzhfzrq;
}
public Date getSwdjzrq() {
return this.swdjzrq;
}
public void setSwdjzrq(Date swdjzrq) {
this.swdjzrq = swdjzrq;
}
}
////////////////////////////////////////////////////////////////
hbm.xml的代码:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!--
Mapping file autogenerated by MyEclipse Persistence Tools
-->
<hibernate-mapping>
<class name="cn.com.cssnj.ntsh.po.TFpHyyzkprdb" table="t_fp_hyyzkprdb" schema="dbo" catalog="nsfw">
<id name="gzlh" type="java.lang.String">
<column name="GZLH" length="21" />
<generator class="assigned" />
</id>
<property name="yyzhfzrq" type="java.util.Date">
<column name="YYZHFZRQ" length="10" />
</property>
<property name="swdjzrq" type="java.util.Date">
<column name="SWDJZRQ" length="10" />
</property>
</class>
</hibernate-mapping>
/////////////////////////////////
调用在这里:
import java.util.Date;
import cn.com.cssnj.ntsh.po.TFpHyyzkprdb;
TFpHyyzkprdb po = null;
po = (TFpHyyzkprdb)this.ihibernatedao.findByPk("cn.com.cssnj.ntsh.po.TFpHyyzkprdb", gzlh);
//////////////////////////
/**
* 根据对象键值返回对象实例。
*/
public Object findByPk(String className, Serializable pk) throws Exception {
LogUtil.debug("getting obj instance with pk: ");
try {
Object instance = (Object) getHibernateTemplate()
.get(className, pk);
return instance;
} catch (RuntimeException re) {
LogUtil.error("get failed", re.fillInStackTrace());
throw re;
}
}