hibernate怎么插入时间?数据库时间类型是datetime,实体时间是java.util.Date,映射文件没写类型属性 20
插入newDate()然后getSession().save(obj)报错22:18:49,890WARNJDBCExceptionReporter:233-SQLErr...
插入new Date() 然后getSession().save(obj) 报错
22:18:49,890 WARN JDBCExceptionReporter:233 - SQL Error: 0, SQLState: 22001
22:18:49,892 ERROR JDBCExceptionReporter:234 - Data truncation: Incorrect datetime value: '' for column 'regist_time' at row 1
22:18:49,896 ERROR Dispatcher:38 - Exception occurred during processing request: could not insert: [cn.wjl.book.user.entity.User]
org.hibernate.exception.DataException: could not insert: [cn.wjl.book.user.entity.User]
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:102)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
at org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningDelegate.java:63)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2346)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2853)
Caused by: com.mysql.jdbc.MysqlDataTruncation: Data truncation: Incorrect datetime value: '' for column 'regist_time' at row 1 展开
22:18:49,890 WARN JDBCExceptionReporter:233 - SQL Error: 0, SQLState: 22001
22:18:49,892 ERROR JDBCExceptionReporter:234 - Data truncation: Incorrect datetime value: '' for column 'regist_time' at row 1
22:18:49,896 ERROR Dispatcher:38 - Exception occurred during processing request: could not insert: [cn.wjl.book.user.entity.User]
org.hibernate.exception.DataException: could not insert: [cn.wjl.book.user.entity.User]
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:102)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
at org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningDelegate.java:63)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2346)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2853)
Caused by: com.mysql.jdbc.MysqlDataTruncation: Data truncation: Incorrect datetime value: '' for column 'regist_time' at row 1 展开
- 你的回答被采纳后将获得:
- 系统奖励15(财富值+成长值)+难题奖励10(财富值+成长值)+提问者悬赏20(财富值+成长值)
展开全部
主要`看你的实体的类型和数据库表中列的类型对不对应`不对应肯定不行
一般数据库sql Server 是timestamp (我的拼写可能是错的) 这个是参数是long
所以
private Timestamp createTime;
***.setCreateTime(new Date());
一般这样
实体类最好用hibernate反向生成
一般数据库sql Server 是timestamp (我的拼写可能是错的) 这个是参数是long
所以
private Timestamp createTime;
***.setCreateTime(new Date());
一般这样
实体类最好用hibernate反向生成
追问
我是mysql,而且***.setCreateTime(new Date());报错
追答
你的代码里有这句还是怎么的`我只是给你举个例子`
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询