关于用getCurrentSession(),忘记在hibernate.cfg.xml 中配置
在集成Hibernate的环境下(例如Jboss),要在hibernate.cfg.xml中session-factory段加入:
1 <property name="current_session_context_class">jta</property>
在不集成Hibernate的环境下(例如使用JDBC的独立应用程序),在hibernate.cfg.xml中session-factory段加入:
1 <property name="current_session_context_class">thread</property>
org.hibernate.MappingException: Unknown entity: com.hb.model.Group
对于annotation方式,找不到实体类,一般是忘记加@Entity,或者是忘记在hibernate.cfg.xml中加入映射字段。
本文详细介绍了在不同环境下(如Jboss和独立JDBC应用程序)使用Hibernate时,如何正确配置getCurrentSession()方法所需的属性。同时,针对常见的MappingException错误,提供了检查实体类注解和配置的解决方案。

被折叠的 条评论
为什么被折叠?



