Hibernate timestamp 问题

    技术2022-05-11  133

    遇到一个奇怪的问题:

    Demo.hbm.xml 文件包括:

    <property name="symbol" column="entid" type="string" length="10" /><property name="donetime" column="donetime" type="timestamp" length="19"/><property name="status" column="status" type="integer" length="11"/><property name="mttime" column="mttime" type="timestamp" length="19"/>

    更新记录时方法如下:

    ...

    DemoBean bean =(DemoBean ) session.find("...").get(0);

    bean.setDonetime(new Date());

    bean.setStatus(1);         

    session.update(bean);

    ...

    发现执行更新操作后 : symbol字段被改成乱码,而且随机的,每次都不一样。
    [当前的解决方法]:

    DemoBean bean =(DemoBean ) session.find("...").get(0);

    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    bean.setDonetime(sdf.parse(sdf.format(new Date())));

    bean.setStatus(1);         

    session.update(bean);

     

    继续关注此类问题的解决方法............................

    最新回复(0)