`

org.hibernate.TransactionException: JDBC begin transaction failed:

阅读更多
启动tomcat时报了下面的错:
=2013-08-06 10:52:37,849 ERROR [Timer-5] timer.SystemMonitoringTimer (SystemMonitoringTimer.java:331)     -  oops, got an exception:
org.springframework.transaction.CannotCreateTransactionException: Could not open Hibernate Session for transaction; nested exception is org.hibernate.TransactionException: JDBC begin transaction failed: 
	at org.springframework.orm.hibernate4.HibernateTransactionManager.doBegin(HibernateTransactionManager.java:440)
	at org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:371)
	at org.springframework.transaction.interceptor.TransactionAspectSupport.createTransactionIfNecessary(TransactionAspectSupport.java:335)
	at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:105)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
	at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:90)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
	at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
	at $Proxy22.getAllThresholdInfo(Unknown Source)
	at com.xxxxxxx.oam.systemmonitoring.timer.SystemMonitoringTimer.run(SystemMonitoringTimer.java:108)
	at java.util.TimerThread.mainLoop(Timer.java:512)
	at java.util.TimerThread.run(Timer.java:462)
Caused by: org.hibernate.TransactionException: JDBC begin transaction failed: 
	at org.hibernate.engine.transaction.internal.jdbc.JdbcTransaction.doBegin(JdbcTransaction.java:76)
	at org.hibernate.engine.transaction.spi.AbstractTransactionImpl.begin(AbstractTransactionImpl.java:160)
	at org.hibernate.internal.SessionImpl.beginTransaction(SessionImpl.java:1309)
	at org.springframework.orm.hibernate4.HibernateTransactionManager.doBegin(HibernateTransactionManager.java:399)
	... 11 more
Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

The last packet successfully received from the server was 9,961 milliseconds ago.  The last packet sent successfully to the server was 0 milliseconds ago.
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
	at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
	at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1074)
	at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:3052)
	at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:2938)
	at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3481)
	at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1959)
	at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2109)
	at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2642)
	at com.mysql.jdbc.ConnectionImpl.setAutoCommit(ConnectionImpl.java:5034)
	at com.mchange.v2.c3p0.impl.NewProxyConnection.setAutoCommit(NewProxyConnection.java:881)
	at org.hibernate.engine.transaction.internal.jdbc.JdbcTransaction.doBegin(JdbcTransaction.java:72)
	... 14 more
Caused by: java.io.EOFException: Can not read response from server. Expected to read 4 bytes, read 0 bytes before connection was unexpectedly lost.
	at com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:2497)
	at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:2949)
	... 22 more



发现报了该错后并不影响系统的功能,事务数据库操作什么的都是OK的,这个错误比较奇怪:如果事务无法开启,那后面的数据库操作应该都无法进行才对呀,可是事实上又不是这样

后来发现是每次把服务器加电开启时才会报这个错,由于我的mysql tomcat等服务都是在开机时自启动的或者是被watchdog自动叫起来的,于是就在想是不是在开机时mysql服务没有完全启动引起的,后来经过测试确定是该原因


于是在tomcat的startup.sh脚本中加上以下语句:

#判断进程mysqld 是否存在,如果不存在就启动它
echo "check The mysqld whether running"
PIDS=`ps -ef |grep mysqld |grep -v grep | awk '{print $2}'`
while [ "$PIDS"x == ""x ]; do
    echo "The mysqld is not running"
    service mysqld start
    sleep 5
    PIDS=`ps -ef |grep mysqld |grep -v grep | awk '{print $2}'`
done
echo "The mysqld is running"


这样就避免了该错误的发生
分享到:
评论
1 楼 无双Rama 2013-09-12  
alter table 表名 modify column 字段名 类型;
例如
数据库中user表 name字段是varchar(30)
可以用
alter table user modify column name varchar(50) ;
alter table LocCondTask modify column Reserved1 varchar(100) ;

相关推荐

    ERRORLOG

    org.hibernate.TransactionException: JDBC rollback failed

    Could not roll back Hibernate transaction.doc

    nested exception is org.hibernate.TransactionException: JDBC rollback failed 这表明Hibernate事务回滚操作失败,导致事务不能正确回滚。 二、问题原因 该问题的主要原因是手动对数据库做了些操作,导致...

    Hibernate4(关系映射-事务-原理-性能和二级缓存-最佳实践)

    3. 原理:Hibernate底层依赖于JDBC来与数据库进行交云,但它隐藏了JDBC API的复杂性。Hibernate通过使用Session和Transaction对象来管理与数据库的交互,它还提供了一个查询语言HQL用于对象查询。Hibernate的原理还...

    Hibernate配置常见错误

    错误表现:事务提交时出现“org.hibernate.TransactionException: Transaction was marked for rollback only; cannot commit”异常。 解决方案:检查事务的回滚规则,确保在try-catch块中正确处理事务。对于Spring...

    hibernate错误汇总

    错误九:Exception in thread "main" org.hibernate.TransactionException: nested transactions not supported 错误原因:Hibernate不支持嵌套事务,即在一个事务中开启另一个事务。这通常是由于在已经处于事务...

    TransactionScope和分布式事务

    但当数据库运行在集群环境下,分布式事务的复杂性暴露出来,特别是Microsoft Distributed Transaction Coordinator (MSDTC)的问题。MSDTC作为集群资源的一部分,可能出现的故障会导致难以排查的错误,尤其是在大规模...

    前端-后端java的Util类的工具类

    │ hibernate.cfg.xml │ HibernateDaoImpl.java │ HibernateSessionFactory.java │ HibernateUtil.java │ JsonUtil.java │ list.txt │ log4j.properties │ messageResource_zh_CN.properties │ spring.xml ...

    SPRING API 2.0.CHM

    HibernateInterceptor HibernateJdbcException HibernateJdbcException HibernateJpaDialect HibernateJpaVendorAdapter HibernateObjectRetrievalFailureException HibernateObjectRetrievalFailureException...

    Hibernate3.2 官方用户手册

    ### Hibernate 3.2 官方用户手册知识点详解 #### 一、概述 Hibernate 是一款开源的对象关系映射 (ORM) 工具,用于 Java 应用程序与数据库交互。它能够将 Java 对象自动持久化到关系型数据库中,从而简化了数据访问...

    spring声明式事务处理demo

    <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> <!-- 数据库连接配置 --> <bean id="transactionManager" class="org.springframework.jdbc.datasource....

    DBFlowBasic

    .beginTransaction(new Transaction() { @Override protected void onRun() throws TransactionException { // 在这里执行数据库操作 User user = new User().name("Jane").email("jane@example.com"); user....

    事务的使用方法

    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <!-- 启用基于注解的事务管理 --> <tx:annotation-driven transaction-manager=...

    spring_aop

    public void handleException(TransactionException ex) { // 处理异常并回滚事务 } @After("execution(* com.example.service.TransactionService.*(..))") public void commitTransaction() { // 提交事务 ...

    无处不在的Spring AOP事务及踩过的坑

    为确保事务正确回滚,可以显式地抛出`TransactionException`或者使用`@Transactional(rollbackFor = Exception.class)`。 3. **事务边界**:`@Transactional`只对被代理的方法有效。如果事务性方法内部调用了非事务...

    dmrkved.rar_Java_

    3. **TransactionException.java** - 这个文件可能定义了一个自定义的异常类,用于在交易过程中捕获和处理错误或异常情况。 4. **i3package-info.java** - 这个文件通常用于提供包级别的注释,可能包含了关于这个包...

    详细介绍Spring事务管理

    TransactionStatus getTransaction(TransactionDefinition definition) throws TransactionException; void commit(TransactionStatus status) throws TransactionException; void rollback(TransactionStatus ...

    PHP ORM(面向对象PDO数据库框架&API框架)

    pdo_transaction($db, function($db) use($user, $userInfo) { $result = $user->insert($db); if (!$result[0]) throw new TransactionException(PDO_ERROR_CODE, '注册用户失败', $result); $user->reset(); ...

Global site tag (gtag.js) - Google Analytics