hibernate死锁问题

并发量很大,出现了死锁,各位有没遇到过这样的问题?
下面贴出代码,只做了插入操作,插入也会出现死锁吗?


public class ICDatabase {

Object mainObject = null;

public void save(Set mainTable) throws InfoCageException {
Transaction transaction = null;
Session session = null;

try {
session = HibernateSessionFactory.currentSession();
transaction = session.beginTransaction();
Iterator iterator = mainTable.iterator();
if (iterator != null) {
while (iterator.hasNext()) {
mainObject = iterator.next();
session.save(mainObject);
clear();
}
transaction.commit();
}
}
catch (Exception exception) {
try {
if (transaction != null)
transaction.rollback();
}
catch (Exception e) {
InfoCageLogging.writeError(e, InfoCodes.ROLLBACK_ERROR);
}
throw new InfoCageException(ErrorCodes.DATABASE_UPDATE_ERROR, exception);

}
finally {
if (session != null) {
try {
HibernateSessionFactory.closeSession();
clear();
}
catch (Exception e) {
InfoCageLogging.writeError(e, InfoCodes.CLOSE_SESSION_ERROR);
}
}
}
}


void clear() {
mainObject = null;
}
}

在事务提交时发生这样的错误:

事务(进程 ID 84)与另一个进程已被死锁在 lock 资源上,且该事务已被选作死锁牺牲品。请重新运行该事务。

原因估计你使用事务锁定一个比较长时间的批处理操作,使用Hibernate批处理命令试验看看。

也就是说当并发时,线程被堵塞了,并且大批量的数据插入到数据库时间太长,导致出现死锁吗?
insert加的写锁吗?如果是写锁还真有可能会出现这样的问题呢

试了一下午依然不会出现死锁的问题,不过有内存溢出现象,没头绪啊