日期:2014-05-17  浏览次数:20598 次

ssh2开发中属性可以为空问题
我用了mysql数据库,然后在日期字段createTime中设置类型为timestamp,默认值CURRENT_TIMESTAMP,这样的话当我加入一条新纪录时mysql中该字段会自动生成时间,在纯jsp开发中我一直这么做的,没出现问题,然后当我用ssh2开发时当我保存新纪录时出现了下面异常:

 Exception occurred inside getter of com.test.bean.News.createTime; nested exception is org.hibernate.PropertyAccessException: Exception occurred inside getter of com.test.bean.News.createTime


我hbm.xml中createTime是这样配置:
<property name="createTime" type="string" column="createTime">
</property>

News类中是这样:
private String createTime;
   
public String getCreateTime() {
return createTime.substring(0, 10);
}
public void setCreateTime(String createTime) {
this.createTime = createTime;
}

我改如何正确配置<property>属性才能正确改正,之所以怀疑这是因为当我把上面那段配置去掉后就可以正常保存了,然而却出现在其他调用时间页面的地方时间显示不出来了



------解决方案--------------------
属性为空 怎么个空法?
------解决方案--------------------
<property name="createTime" type="timestamp" column="createTime" />类型应该改为timestamp啊。。

还不行的话。。加一个default属性。。设置默认值试试。。