`

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.

分享到:
评论

相关推荐

    Web-Related-Examples

    【标题】"Web-Related-Examples" 涵盖了与Web开发相关的各种实例,主要集中在Java编程语言上。这个项目可能是一个集合,包含了不同类型的Web应用开发中的关键概念和技术的实战展示。以下是对这些知识点的详细说明: ...

    雪雅服饰的设计实现分析论文.doc

    In Xueya Clothing's system, Hibernate is used for handling database operations related to user registration, product management, and order processing. The choice of MySQL as the database management ...

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

    解析Oracle中多表级联删除的方法

    DELETE FROM "U_WEN_BOOK"."SOME_DEPENDENT_TABLE" WHERE "RELATED_COLUMN" = :OLD."FAR_ID"; END; / ``` 这个触发器会在尝试删除`FARTAB`表中的记录前,先删除`SOME_DEPENDENT_TABLE`中相关记录。 以上三种方法...

    mpb.zip_document_mpb_project

    因此,我们可以预期在这个项目中,开发者会使用Java标准库、框架(如Spring Boot、Hibernate)以及其他Java工具来构建系统。 标签"document mpb project"进一步强调了文档在项目中的重要性。良好的文档不仅能够提高...

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

    jdbc.rar_Links

    【描述】"Related links about jdbc" 暗示这个压缩包可能包含了指向有关JDBC的各种在线资源的链接,如教程、API文档、示例代码、最佳实践、社区论坛等。这些链接可以帮助开发者深入理解JDBC的工作原理,学习如何有效...

    XDoclet in Action

    This chapter focuses on using XDoclet for data persistence, including ORM frameworks like Hibernate. Key topics include: - **Data Persistence Overview**: An introduction to data persistence in Java ...

    Manning - Eclipse In Action.pdf

    - **Dynamic Web Applications**: Support for building dynamic web applications using technologies like JSP, Servlets, and frameworks like Spring and Hibernate. #### Part II: Extending Eclipse **...

    Spring面试题汇总

    - `spring-orm`模块提供了对JPA、Hibernate等ORM框架的集成。 - `spring-oxm`处理对象XML映射,如JAXB、Castor、JiBX和XStream。 - `spring-jms`提供了生产和消费消息的功能,与`spring-messaging`模块集成。 10...

    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