hibernate批量删除时出现的问题
以下是我的批量删除的代码:
String[] studentIDs = request.getParameterValues("VoteOption1");
Collection entities = new ArrayList();
for (int i = 0; i < studentIDs.length; i++) {
T_student student = t_studentDAO.read(Integer.parseInt(studentIDs[i]));
entities.add(student);
}
t_studentDAO.deleteAll(entities);
以下是进行操作时出现的异常信息:
严重: Servlet.service() for servlet action threw exception
org.hibernate.HibernateException: Illegal attempt to associate a collection with two open sessions
at org.hibernate.collection.AbstractPersistentCollection.setCurrentSession(AbstractPersistentCollection.java:410)
at org.hibernate.event.def.OnUpdateVisitor.processCollection(OnUpdateVisitor.java:40)
at org.hibernate.event.def.AbstractVisitor.processValue(AbstractVisitor.java:101)
at org.hibernate.event.def.AbstractVisitor.processValue(AbstractVisitor.java:61)
请大家帮忙看看是哪里的问题,谢谢!
String[] studentIDs = request.getParameterValues("VoteOption1");
Collection entities = new ArrayList();
for (int i = 0; i < studentIDs.length; i++) {
T_student student = t_studentDAO.read(Integer.parseInt(studentIDs[i]));
entities.add(student);
}
t_studentDAO.deleteAll(entities);
以下是进行操作时出现的异常信息:
严重: Servlet.service() for servlet action threw exception
org.hibernate.HibernateException: Illegal attempt to associate a collection with two open sessions
at org.hibernate.collection.AbstractPersistentCollection.setCurrentSession(AbstractPersistentCollection.java:410)
at org.hibernate.event.def.OnUpdateVisitor.processCollection(OnUpdateVisitor.java:40)
at org.hibernate.event.def.AbstractVisitor.processValue(AbstractVisitor.java:101)
at org.hibernate.event.def.AbstractVisitor.processValue(AbstractVisitor.java:61)
请大家帮忙看看是哪里的问题,谢谢!
...全文
相关推荐
jsp Hibernate批量更新和批量删除处理代码
批量更新是指在一个事务中更新大批量数据,批量删除是指在一个事务中删除大批量数据。
hibernate批量删除
在我们的Java项目中,批量更新是指在一个事务中更新大批量数据,批量删除是指在一个事务中删除大批量数据。批量删除虽然在Hibernate里也可以实现,但因Hibernate的实现机制是一个一个删除,在数量大的情况下很影响效率;其实Hibernate提供的JDBC接口,可以方便的进行批量的更新和删除。
在Hibernate中处理批量更新和批量删除
在Hibernate中处理批量更新和批量删除
Hibernate批量更新与删除实例浅析
绍Hibernate的批量更新与删除
Java中Hibernate的批量插入
Hibernate完全以面向对象的方式来操作数据库,当程序里以面向对象的方式操作持久化对象时,将被自动转换为对数据库的操作。例如我们调用Session的delete()方法,来删除持久化对象,Hibernate将负责删除对应的数据记录;当我们执行持久化对象的setter方法时,Hibernate将自动转换为底层的update语句,修改数据库的对应记录。 问题是:如果我们需要同时更新100000条记录,是不是要逐一加载100000条记录,然后依次调用setter方法——这样不仅烦琐,数据访问的性能也十分糟糕。为了面对这种批量处理的场景,Hibernate提供了批量处理的解决方案。下面分别


Web 开发
