1. Cannot get .currentSession()
org.hibernate.HibernateException: No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here
at org.springframework.orm.hibernate3.SpringSessionContext.currentSession(SpringSessionContext.java:63)
at org.hibernate.impl.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:622)
@Override public void refreshObject() { Test test1; test1 = testDaoLocator.findById("1"); System.out.println("C1: " + test1.getC2()); test1.setC2("ddd"); } public Test findById(String id) { Test instance = (Test) this.getSessionFactory().getCurrentSession().get(Test.class, id); return instance; }
Cause:
There is no any session.
Solution 1 is using "this.getSessionFactory().openSession()" intead.
Solution 2 is adding transaction between the method like below:
<aop:config> <aop:advisor pointcut="execution(* lin.service..refreshObject(..))" advice-ref="requiresNewTxAdvice" /> </aop:config> <tx:advice id="requiresNewTxAdvice" transaction-manager="transactionManager"> <tx:attributes> <tx:method name="*" propagation="REQUIRES_NEW" /> </tx:attributes> </tx:advice>
2.
相关推荐
This updated edition includes the new Hibernate 5.0 framework as well as coverage of NoSQL, MongoDB, and other related technologies, ranging from applications to big data. Beginning Hibernate is ...
This updated edition includes the new Hibernate 5.0 framework as well as coverage of NoSQL, MongoDB, and other related technologies, ranging from applications to big data. Beginning Hibernate is ...
Hibernates goal is to relieve the developer from 95 percent of common data persistence related programming tasks. Hibernate may not be the best solution for data-centric applications that only use ...
Lastly, this book covers advanced topics related to persistence architecture and design patterns, and is ideal for beginning developers looking to learn more in these areas. Table of Contents ...
relieve the developer from 95% of common data persistence-related programming tasks by eliminating the need for manual, hand-crafted data processing using SQL and JDBC. However, unlike many other ...
Interview questions about core Java, EJB, JSP, Servlets, Struts, Hibernate, JDBC and all related information. All from fresh interviews of Google, Amazon, Goldman Sachs, Morgan Stanley and other big ...
Divided into three parts, the book provides an exhaustive coverage of topics taught in advanced Java and other related subjects. It first introduces important language features such as Reflection, ...
Discover the key Spring framework-related technology standards such as Spring core, Spring-AOP, Spring data access frameworks, and Spring testing to develop robust Java applications easily and rapidly...
He is a certified JBoss instructor and teaches courses in Hibernate and the JBoss Application Server. Javid is also an Agile evangelist and spends a large portion of his time transforming, coaching, ...
His areas of interest include a wide range of Java-related technologies (Servlets, JSP, JAXB, JAXP, JMS, JMX, JAX-RS, JAX-WS, Hibernate, Spring Framework, Liferay Portal, and Eclipse RCP), cloud ...
Hibernate, JPA 2, Tiles, Thymeleaf, and WebSocket. The focus of the book is on using Java configuration classes, lambda expressions, Spring Boot, and reactive programming. We share our insights and ...
Contents at a Glance Foreword . . . . . . . . ....About the Author ....About the Technical Reviewers ....Acknowledgments....Introduction ....■CHAPTER 1 Introduction ....■CHAPTER 2 Structure of the NetBeans Platform ....