Spring 3.1.1 与 hibernate 4.1 注解配置

2024-02-17

我正在使用 spring3.1.1 和 hibernate 4.1 设置新项目。 当我运行我的项目时,出现以下错误

java.lang.NoSuchMethodError: org.hibernate.SessionFactory.getCurrentSession()Lorg/hibernate/classic/Session;
at com.humancapital.dao.TestModelDAOImpl.getTestModelList(TestModelDAOImpl.java:22)

我的applicationContext.xml

 <?xml version="1.0" encoding="UTF-8"?>

       
        <context:component-scan base-package="com.example"/>
                                      
        <!-- Use @Transaction annotations for managing transactions  -->    
        <tx:annotation-driven transaction-manager="transactionManager"/>
                                      
        <!-- PropertyConfiguer -->
        <bean id="propertyCongigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
            <property name="location" value="/WEB-INF/config/jdbc/jdbc.properties"></property>
        </bean>
        
        <!--  DataSource connection -->
        <bean id="myDataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
            <property name="driverClassName" value="${jdbc.driverClassName}"></property>
            <property name="url" value="${jdbc.url}"></property>
            <property name="username" value="${jdbc.username}"></property>
            <property name="password" value="${jdbc.password}"></property>  
        </bean>
        
        <!-- Hibernate SessionFactory -->
        <bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
            <property name="dataSource" ref="myDataSource"></property>
            <property name="annotatedClasses">
                <list>
                    <value>com.humancapital.dao.TestModel</value>
                </list>
            </property>
            <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
                <prop key="hibernate.show_sql">true</prop>
                <prop key="hibernate.hbm2ddl.auto">update</prop> 
            </props>
            </property>
        </bean>
        

        
        <bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
            <property name="sessionFactory" ref="sessionFactory"></property>
        </bean>
        
        <context:annotation-config/>
        
        <bean id="testModelDAO" class="com.example.dao.TestModelDAOImpl"></bean>

MyDAOImpl

@Repository
public class TestModelDAOImpl implements TestModelDAO {

@Autowired
private SessionFactory sessionFactory;
public void setSessionFactory(SessionFactory sessionFactory){
    this.sessionFactory = sessionFactory;
}

@SuppressWarnings("rawtypes")
@Override
    @Transactional(readOnly=true,propagation=Propagation.REQUIRES_NEW)
public List getTestModelList() {
    System.out.println(sessionFactory.toString());
    return sessionFactory.getCurrentSession().createCriteria(TestModel.class).list();
}
}

我已经添加了我的依赖罐,请建议我

antlr-2.7.7.jar
antlr-runtime-3.0.jar
commons-collections-3.2.1.jar
commons-dbcp-1.4.jar
commons-fileupload-1.2.jar
commons-lang-2.4.jar
commons-logging.jar
commons-pool-1.5.4.jar
dom4j-1.6.1.jar
ejb3-persistence-3.3.1.jar
hibernate-commons-annotations-4.0.1.Final.jar
hibernate-core-4.1.1.Final.jar
hibernate-entitymanager-4.1.1.Final.jar
hibernate-jpa-2.0-api-1.0.1.Final.jar
hibernate-validator-4.0.2.GA.jar
jackson-core-asl-1.9.2.jar
jackson-jaxrs-1.8.5.jar
jackson-mapper-asl-1.9.2.jar
javassist-3.15.0-GA.jar
jboss-logging-3.1.0.CR2.jar
jboss-transaction-api_1.1_spec-1.0.0.Final.jar
json-lib-2.3-jdk13.jar
jstl-1.2.jar
jta-1.1.jar
log4j-1.2.14.jar
mail.jar
mysql-connector-java-5.0.8-bin.jar
org.springframework.aop-3.1.1.RELEASE.jar
org.springframework.asm-3.1.1.RELEASE.jar
org.springframework.aspects-3.1.1.RELEASE.jar
org.springframework.beans-3.1.1.RELEASE.jar
org.springframework.context.support-3.1.1.RELEASE.jar
org.springframework.context-3.1.1.RELEASE.jar
org.springframework.core-3.1.1.RELEASE.jar
org.springframework.expression-3.1.1.RELEASE.jar
org.springframework.jdbc-3.1.1.RELEASE.jar
org.springframework.jms-3.1.1.RELEASE.jar
org.springframework.js-2.0.8.RELEASE.jar
org.springframework.orm-3.1.1.RELEASE.jar
org.springframework.oxm-3.1.1.RELEASE.jar
org.springframework.test-3.1.1.RELEASE.jar
org.springframework.transaction-3.1.1.RELEASE.jar
org.springframework.web.servlet-3.1.1.RELEASE.jar
org.springframework.web-3.1.1.RELEASE.jar
servlet-api.jar
slf4j-api-1.6.1.jar
slf4j-log4j12-1.6.1.jar
slf4j-simple-1.6.1.jar
spring-modules-validation-0.7.jar
standard.jar

请帮助我完成项目设置。 请提出一些建议,我们在建立新的项目结构时需要集中精力,以便将来的升级需要较少的更改。

抱歉,我是 stackoverflow 的新手,我不知道如何回复命令


发生这种情况是因为您处于冬眠状态。current_session_context_class启用属性

在将 Hibernate 与 Spring 结合使用时,切勿使用该属性,因为它会破坏正确的会话和事务管理。只有当您在 JTA 环境中使用 Spring 和 Hibernate 时才需要设置此属性,否则不要使用它。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Spring 3.1.1 与 hibernate 4.1 注解配置 的相关文章

随机推荐

  • 使用 jQuery 无法找到动态添加的 HTML 元素

    我正在 HTML 中实现一个树浏览器 单击节点时 我调用一个添加该节点的子元素的函数 到目前为止 一切都很好 我现在想立即调用其中一个子元素的单击处理程序来展开它 我的问题是 jQuery 找不到刚刚添加的子元素 当我在调试器中单步调试时
  • x/y 坐标的排序向量

    我有一个向量 u32 u32 表示 10 x 10 网格上坐标的元组 坐标未排序 因为标准sort函数也没有产生我想要的结果 我为他们编写了一个这样的排序函数 vec sort by a b if a 0 gt b 0 return Ord
  • 使用 SQL 批量更新记录

    我在 SQL Server 2008 环境中有两个表 其结构如下 Table1 ID DescriptionID Description Table2 ID Description Table1 DescriptionID 映射到Table
  • 在依赖注入中检查 null 的更好方法

    通过构造函数使用依赖项注入时 我始终需要在将实例传递给内部属性之前检查是否为空 例如 public UserManager User user IStateManager stateManager if user null throw ne
  • 使用谷歌直方图创建日期直方图

    如何创建适用于日期的 Google 直方图 1 我已经放置了示例代码 带有工作号码和非工作日期示例 http jsfiddle net Qquse 417 http jsfiddle net Qquse 417 和下面的代码 2 1 htt
  • 为什么 Spring 允许在私有方法上进行控制器注释的请求映射?

    今天刚刚在 Spring MVC 控制器类中遇到了这个 RequestMapping value foo method RequestMethod GET private String doThing final WebRequest re
  • 为什么表单提交会打开新窗口/选项卡?

    我发现了很多问题 如何在新窗口中打开表单结果 https stackoverflow com search q spring 20form 20new 20window 但我面临着相反的问题 我有表格
  • 使用 twitter bootstrap 3 将 9 列布局居中

    我的代码就像 div class container fluid div class row div class col md 3 div div class col md 3 div div class col md 3 div div
  • 使用 Google Analytics 管理 API 和应用脚本提取 GA4 媒体资源列表

    想知道是否有人有使用新的 Analytics Admin API 将 GA 帐户和属性列表导出到电子表格的经验 我过去曾使用管理 API 来实现此目的 但这限制了我们只能使用 UA 属性 我希望也能在此处包含 GA4 属性 我尝试过将旧脚本
  • simplemembership MVC4 通过 userId 获取用户名

    使用 MVC4 和 SIMPLEMEMBERSHIP 的人知道如何通过 userId 获取用户名 用户未登录 我想删除它 要删除我必须使用 Membership DeleteUser string username 你可以使用GetUser
  • 连接来自不同服务器的表

    有什么建议如何在存储过程中连接来自不同服务器的表吗 如果没有更多细节 很难给出直接的例子 但基本思想如下 首先 在存储过程之外 主机服务器 存储过程所在的服务器 必须了解第二台服务器 包括 可能 登录信息 在您的主服务器上 运行sp add
  • TestCafe——断言元素可见的正确方法

    根据各种论坛讨论 TestCafe 文档以及尝试比较结果 我仍然不确定哪种是断言页面元素可见的正确 或最佳 方法 await t expect Selector elementId visible ok vs await t expect
  • 使用 Javascript 在 Span 标记内动态插入链接

    我有这个 span class image img src something jpg span 我想使用 javascript 将其转换为 span class image a href domain img src something
  • 如何为我的石头剪刀布游戏编写一套更简洁的代码?

    下面是我在 Web 开发课程中必须进行的石头剪刀布游戏活动的 JS 文件 我能够让一切正常工作 但是我不喜欢 if else 语句使我的代码花费了多长时间 并且想知道如何使其更加简洁并以更少的代码行数实现 const imagePath i
  • 将 div 容器调整为视频大小(也可全屏)

    我正在尝试获取覆盖视频的文本 并根据其大小调整进行相应的操作 目前我的麻烦是使视频容器的大小与播放器相同 以及全屏模式 我的容器是相对定位的 我的视频和文本叠加 div 是绝对定位的 HTML div div
  • 使用 SoX 将 mp3 文件分割为 TIME 秒

    我需要将 mp3 文件分割成片TIME每秒 我试过了mp3splt 但如果输出是 它对我不起作用不到1分钟 是否可以这样做 sox file in mp3 file out mp3 trim START LENGTH 当我不知道mp3文件时
  • 使用 spring 集成 aws 轮询 S3 存储桶中的文件并进行处理

    我需要轮询 S3 存储桶中的文件 并在任何文件可用时立即拾取并处理它们 我需要使用 Spring Integration 和 spring integration aws 来完成此操作 所以到目前为止我的代码看起来像这样 public Am
  • 将不存在的元素添加到 DynamoDB 中的数组

    我正在尝试更新项目属性 即字符串列表 仅当属性不存在时我才可以更新 追加 该属性吗 类似于 list append 和 if not exists var 参数 UpdateExpression 设置朋友 list append if no
  • 增加 ggplot 标题中下划线的大小

    我正在尝试增加 ggplot 标题中下划线的大小 宽度 厚度 我尝试过使用尺寸 宽度和长度 但没有成功 这是我所做的一个例子 test lt tibble x 1 5 y 1 z x 2 y ggplot test aes x z geom
  • Spring 3.1.1 与 hibernate 4.1 注解配置

    我正在使用 spring3 1 1 和 hibernate 4 1 设置新项目 当我运行我的项目时 出现以下错误 java lang NoSuchMethodError org hibernate SessionFactory getCur