在进行HQL查询是出现的错误:
使用iterate进行查询,代码如下,报出
Can't start a cloned connection while in manual transaction mode.
错误,
- Iterator iter = session.createQuery("from Student").iterate();
- while(iter.hasNext()) {
- Student student = (Student)iter.next();
- System.out.println(student.getName());
- }
但是使用,如下代码进行查询,却没有报错,
- List students = session.createQuery("from Student").list();
- for (Iterator iter=students.iterator(); iter.hasNext();) {
- Student student = (Student)iter.next();
- System.out.println(student.getName());
- }
- System.out.println("---------------------------------------------");
- Iterator iter = session.createQuery("from Student").iterate();
- while(iter.hasNext()) {
- Student student = (Student)iter.next();
- System.out.println(student.getName());
- }
找了相关资料,最后解决了问题,修改连接数据库的URL为
jdbc:microsoft:sqlserver://localhost:1433;DataBaseName=Hibernate_HQL;SelectMethod=cursor
在URL后加入红色标注代码