假设有以下类:
@Transactional public class SubClass extends SuperClass { public void loadDb(){ //数据库操作 } } public class SuperClass { public void savedb() { //数据库操作 } }
savedb是父类的方法,loadDb是子类的方法。如果有以下调用:
@Test public void test(){ SubClass o = new SubClass(); o.savedb();//将会报没有Session的错误 o.loadDb();//正常 }
可以看到在调父类方法时Hibernate报没有Session的错误(org.hibernate.HibernateException: No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here),子类没有问题。
解决办法一:在子类中重载父类方法:
@Transactional public class SubClass extends SuperClass { public void loadDb(){ } @Override public void savedb() { super.savedb(); } }
这样显然繁琐了,子类savedb没有任何新操作。
解决方法二:在父类中标注@Transactional(父类是抽象类也可以):
@Transactional public class SuperClass { public void savedb() { } }
这需要父类的修改权限。
同时可以参考:
相关推荐
然而,在使用 Hibernate 进行数据库操作时,经常会遇到 "No Hibernate Session bound to thread" 的错误信息。本文将详细介绍该错误的解决方案。 错误原因 "No Hibernate Session bound to thread" 错误信息通常是...
然而,在某些特定场景下,我们可能并不需要频繁地打开和关闭Session,这时“Hibernate-nosession”就显得尤为重要。本文将深入探讨Hibernate-nosession的概念、应用场景以及如何在实际代码中实现。 首先,理解什么...
hibernate就会抛出: No Hibernate Session bound to thread, and configuration does not allow creation of one here}异常。 在实际的SSH web应用开发中,我们通常用spring来进行事务的管理。我们一般不会在dao层...
在Java的持久化框架Hibernate中,Session对象是与数据库交互的核心组件,它负责管理对象的持久状态。在处理大量数据或者长时间运行的事务时,合理地管理Session的生命周期至关重要,这就涉及到了Hibernate的Session...
配置tomcat7sqlserver数据连接池java 利用数据源对象建立数据库连接时的错误: Name jdbc is not bound in this Context 解决方案
Name salesDataSource is not bound in this Context,连接池的问题
1. Introduction to Hibernate 1.1. Preface 1.2. Part 1 - The first Hibernate Application 1.2.1. The first class 1.2.2. The mapping file 1.2.3. Hibernate configuration 1.2.4. Building with Ant 1.2.5. ...
branch and bound
本案例重点探讨了Spring如何与两种流行的数据访问技术——JDBC(Java Database Connectivity)和Hibernate——相结合,进行事务管理。事务控制是确保数据库操作一致性、完整性的关键,尤其在多步骤操作中,它能防止...
On a search problem related to branch-and-bound procedures.pdfOn a search problem related to branch-and-bound procedures.pdfOn a search problem related to branch-and-bound procedures.pdfOn a search ...
当遇到`no current session bound to current context`错误时,通常是因为事务管理方式不正确。Hibernate提供了多种会话上下文配置,如`thread`、`jta`等。在这种情况下,推荐使用`thread`配置,确保每个线程都有...
今天在处理bug的时候发现某一个很奇怪的问题,在执行某类操作的时候会报:Invalid parameter number: no parameters were bound,但是该问题在本地或是测试机上测试都没有重现,猜想是否和版本有关,于是就google了...
SQL Server needs to lock data that does not exist! If no rows satisfy the WHERE condition the first time the range is scanned, no rows should be returned on any subsequent scans. Key range locks are ...
**分枝定界法(Branch and Bound)**是一种在离散优化问题中寻找全局最优解的算法,尤其在解决旅行商问题(Traveling Salesman Problem, TSP)时展现出其强大的能力。旅行商问题是一个经典的组合优化问题,目标是...
在spring+hibernate的框架中定时操作数据库,主要是拿到sessionFactory,不会出现no session 和transaction no-bound等问题,由sessionFactory完成对数据的操作,有些包是没有用的,有兴趣的可以自己删除掉
“POINT TO POINT CALLS” means any call made directly between no more than two users on compatible devices that does not utilize POLYCOM’s multipoint bridging technology. POINT TO POINT CALLS may not...
If you do not agree to all of the terms and conditions contained in this EULA, you may not install or use the SOFTWARE. If you have already installed or begun to install the SOFTWARE you should ...
MATLAB分支定界法求解,大家
错误信息: XXXX client has already been bound to another coroutine使用协程客户端时出现以下错误信息:re