基于 Spring hibernate3 struts2 mysql5.0 的SSH项目运行正常,现在要求使用mysql5.6+ ,直接连新的数据库 先报错:
Incorrect datetime value: '' for column 'createtime'
网上说是驱动包和mysql版本不兼容,我就把mysql-connector-java-5.0.4-bin.jar 换成了mysql-connector-java-5.1.36-bin.jar这个错误解决了,可是新的错误来了好多,比如hibernate的乐观锁,数据版本字段
<timestamp name="version" column="version"></timestamp>
总是报错
org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect): [com.pl.domain.Stage#402881455972d669015972e334680006] at org.hibernate.persister.entity.AbstractEntityPersister.check(AbstractEntityPersister.java:1782) at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2425) at org.hibernate.persister.entity.AbstractEntityPersister.updateOrInsert(AbstractEntityPersister.java:2325) at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2625) at org.hibernate.action.EntityUpdateAction.execute(EntityUpdateAction.java:115) at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:279) at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:263) at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:168) at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321) at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:50) at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1028) at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:366) at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:137) at org.springframework.orm.hibernate3.HibernateTransactionManager.doCommit(HibernateTransactionManager.java:558) at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:662) at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:632) at org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:319) at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:116) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171) at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
还有好多好多问题,用mysql5.0 就没有这些错误,一换MySQL5.6就这么多错误。有没有人了解这两个版本的数据库替换时需要改什么。感觉这样头痛医头脚痛医脚,什么时候是个头啊。
这个异常我遇到过,不是driver版本的问题,而是mysql5.6的更新内容中包含了datetime这个type,印象中是支持毫秒级了,而且某个属性不能为空了。当时的做法是把那个datetime的字段类型重新update一把就好了。回复<aclass="referer"target="_blank">@Feng_Yu:我在网上查的换了新的驱动包就解决这个问题了,我感觉换驱动包更方便一些,因为我这是拿的别人的项目,里面非常多的这种类型还有<timestamp>这样的配置,现在主要是第二个报错,好几天没解决。回复<aclass="referer"target="_blank">@颖辉小居:Incorrectdatetimevalue:''forcolumn'createtime'这个异常,修改下SSH的代码就行了,把datetime这种字段给个初始值就行了。您好,您说的遇到过的异常是哪个呢?是Rowwasupdatedordeletedbyanothertransaction(orunsaved-valuemapping吗?
很简单,不用hibernate了。<imgsrc="https://www.oschina.net/js/ke/plugins/emoticons/images/4.gif"alt="">
问题是公司就要用啊,这个项目都用了好几年了,现在就要升级mysql的版本到5.6。其他的尽量不让修改。版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。