`

Hibernate related

 
阅读更多

 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.

分享到:
评论

相关推荐

    Beginning Hibernate: For Hibernate 5

    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 ...

    Beginning.Hibernate.For.Hibernate.5.4th.Edition

    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 ...

    Hibernate Reference Documentation(Hibernate参考手册)

    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 ...

    Spring.Persistence.with.Hibernate.2nd.Edition.1484202694

    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 ...

    hibernate教程

    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 ...

    J2EE Interview Questions

    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 ...

    Advanced.Java.Programming.0199455503

    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, ...

    Learning.Spring.Application.Development.1783987367

    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...

    Manning JBoss in Action: Configuring the JBoss Application Server

    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, ...

    learning rabbitmq

    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 ...

    Pro Spring 5 An In-Depth Guide -Apress(2017)

    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 ...

    The Definitive Guide to NetBeans Platform

    Contents at a Glance Foreword . . . . . . . . ....About the Author ....About the Technical Reviewers ....Acknowledgments....Introduction ....■CHAPTER 1 Introduction ....■CHAPTER 2 Structure of the NetBeans Platform ....

Global site tag (gtag.js) - Google Analytics