first of all if you want to use getcurrentSession() method you need to add these properties to HibernateProperties:
<prop key="hibernate.current_session_context_class">thread</prop>
<prop key="hibernate.transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</prop>
添加后如下:
second thing is from the exception, Hibernate3 doesn't allow you to run queries without starting a transaction. you have to add this to your init method before running the query:
sessionFactory.getCurrentSession().beginTransactio n();
and of course commit it in the end of your unit of work.
分享到:
相关推荐
然而,在使用 Hibernate 进行数据库操作时,经常会遇到 "No Hibernate Session bound to thread" 的错误信息。本文将详细介绍该错误的解决方案。 错误原因 "No Hibernate Session bound to thread" 错误信息通常是...
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/...
Caused by: org.hibernate.HibernateException: Could not instantiate connection provider [org.hibernate.connection.C3P0ConnectionProvider] at org.hibernate.engine.jdbc.connections.internal....
3. Spring框架异常:文档提到“org.springframework.beans.factory.BeanCreationException”和“No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here...
《深入理解Hibernate 5.4.25:关键特性与实战应用》 Hibernate,作为一款强大的对象关系映射(ORM)框架,对于Java开发者来说,是实现数据库操作的重要工具。在面向对象编程的世界里,它简化了数据持久化的复杂性,...
2. `org.hibernate.cfg.Configuration`:配置对象,用于设置Hibernate的属性,如数据库连接信息等。 3. `org.hibernate.HibernateException`:Hibernate抛出的异常类。 4. `org.hibernate.Query`和`org.hibernate ...
由于项目需求的需要,我们引入了连接池。...我们采用了Hibernate,所以可以考虑hibernate自带的连接池机制,但是发现效率不高,而且Hibernate也推荐使用c3p0或Proxool连接池,在我们的项目中采用了Proxool
query.setHint("org.hibernate.fetchSize", 20); // 设置查询结果集大小 query.setFetchSize(20); List<Game> games = query.list(); tx.commit(); } catch (HibernateException e) { if (tx != null) { tx....
2、报错:org.hibernate.HibernateException: No Session found for current thread 意思是必须在transcation.isActive()条件下才能执行, 可以解决办法是:当方法不需要事务支持的时候,使用 Session ...
import org.hibernate.HibernateException; import org.hibernate.Session; import org.hibernate.cfg.Configuration; public class HibernateSessionFactory { private static String CONFIG_FILE_LOCATION = "/...
18. class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"> 19. <property name="dataSource" ref="dataSource" /> 20. <property name="hibernateProperties"> 21. <props> 22...
* Configures and provides access to Hibernate sessions, tied to the * current thread of execution. Follows the Thread Local Session * pattern, see {@link http://hibernate.org/42.html }. */ public ...
错误表现:在Session关闭后尝试访问懒加载属性,抛出“org.hibernate.LazyInitializationException: could not initialize proxy - no Session”异常。 解决方案:理解并合理使用Open Session in View(OSIV)模式...
import org.hibernate.HibernateException; import org.hibernate.SessionFactory; import org.hibernate.cfg.Configuration; ``` 2. **类声明:** ```java public class HibernateUtil { ``` 3. **静态...
2. java.lang.ClassCastException: org.hibernate.annotations.common.reflection.java.JavaReflectionManager cannot be cast to org.hibernate.annotations.common.reflection.MetadataProviderInjector ...
《Hibernate 5.1.5.Final:持久化框架的核心技术与应用》 Hibernate,作为Java领域中的一个著名ORM(对象关系映射)框架,它有效地解决了对象与数据库之间的交互问题,大大简化了数据访问层的开发工作。 Hibernate ...
《Hibernate ORM深度解析》 Hibernate ORM,全称Hibernate Object Relational Mapping,是Java领域中一款广泛应用的开源对象关系映射框架。它为开发者提供了一种将面向对象的模型与传统的关系数据库之间的转换工具...
首先,从 org.hibernate.cfg.Configuration.java 开始,使用 Hibernate 框架实现应用程序,首先就要与 org.hibernate.cfg.Configuration 打交道,要使用 Configuration.buildSessionFactory() 方法获得一个 ...