为了账号安全,请及时绑定邮箱和手机立即绑定

跳出三句SQL语句后一会儿出现事务死锁,后面学生表的插入更新语句不能输出

Hibernate: select max(gid) from grade

Hibernate: select max(sid) from student

Hibernate: insert into grade (gname, gdesc, gid) values (?, ?, ?)

五月 10, 2017 3:40:24 下午 org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions

WARN: SQL Error: 1205, SQLState: 41000

五月 10, 2017 3:40:24 下午 org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions

ERROR: Lock wait timeout exceeded; try restarting transaction

五月 10, 2017 3:40:24 下午 org.hibernate.engine.jdbc.batch.internal.AbstractBatchImpl release

INFO: HHH000010: On release of batch it still contained JDBC statements

Exception in thread "main" org.hibernate.exception.LockTimeoutException: could not execute statement

at org.hibernate.dialect.MySQLDialect$1.convert(MySQLDialect.java:447)

at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:49)

at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:126)

at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:112)

at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:190)

at org.hibernate.engine.jdbc.batch.internal.NonBatchingBatch.addToBatch(NonBatchingBatch.java:62)

at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3124)

at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3587)

at org.hibernate.action.internal.EntityInsertAction.execute(EntityInsertAction.java:103)

at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:453)

at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:345)

at org.hibernate.event.internal.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:350)

at org.hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:56)

at org.hibernate.internal.SessionImpl.flush(SessionImpl.java:1218)

at org.hibernate.internal.SessionImpl.managedFlush(SessionImpl.java:421)

at org.hibernate.engine.transaction.internal.jdbc.JdbcTransaction.beforeTransactionCommit(JdbcTransaction.java:101)

at org.hibernate.engine.transaction.spi.AbstractTransactionImpl.commit(AbstractTransactionImpl.java:177)

at com.imooc.entity.Test.add(Test.java:26)

at com.imooc.entity.Test.main(Test.java:10)

Caused by: java.sql.SQLException: Lock wait timeout exceeded; try restarting transaction

at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:946)

at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2985)

at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1631)

at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1723)

at com.mysql.jdbc.Connection.execSQL(Connection.java:3283)

at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1332)

at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1604)

at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1519)

at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1504)

at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:187)

... 14 more

测试类代码

package com.imooc.entity;


import org.hibernate.Session;

import org.hibernate.Transaction;


import com.imooc.util.HibernateUtil;


public class Test {

public static void main(String[] args) {

add();

}

public static void add(){

Grade g=new Grade("java1","javaee");

Student stu1=new Student("Tom","m");

Student stu2=new Student("Lucy","w");

g.getStudents().add(stu1);

g.getStudents().add(stu2);

Session session=HibernateUtil.getSession();

Transaction tx=session.beginTransaction();

session.save(g);

session.save(stu1);

session.save(stu2);

tx.commit();

HibernateUtil.closeSession(session);

}


}


正在回答

3 回答

我是重新建了一个数据库,在建数据库的时候编码啥的选utf8,就好了

2 回复 有任何疑惑可以回复我~

我把电脑重新启动。。然后。。好了。

1 回复 有任何疑惑可以回复我~

不会截图。。下面的图是老师视频中的,只显示了前三句SQL语句

1 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消
Hibernate初探之一对多映射
  • 参与学习       42171    人
  • 解答问题       295    个

Hibernate中一对多关联映射配置,以及cascade和inverse属性作用

进入课程

跳出三句SQL语句后一会儿出现事务死锁,后面学生表的插入更新语句不能输出

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信