当前位置: 首页 > 面试题库 >

将Hibernate 5.2与Spring框架4.x集成

周昊乾
2023-03-14
问题内容

我正在使用最新的稳定Spring版本(4.2.6.RELEASE)。

将Hibernate从5.1升级到5.2,并将hibernate-entitymanager依赖项更改为hibernate- core适当的hibernate文档后:https : //github.com/hibernate/hibernate-
orm/wiki/Migration-Guide—5.2

我没有收到任何编译错误,但是我的所有测试都因以下堆栈跟踪而失败:

Jun 06, 2016 12:00:38 PM org.springframework.test.context.TestContextManager beforeTestMethod
WARNING: Caught exception while allowing TestExecutionListener [org.springframework.test.context.transaction.TransactionalTestExecutionListener@548b7f67] to process 'before' execution of test method [public void com.rh.cores.architecture.tests.units.person.PersonTest.add_iranianNaturalPersonDateIsInvalid_preventSaving()] for test instance [com.rh.cores.architecture.tests.units.person.PersonTest@7f9e8421]
org.springframework.transaction.CannotCreateTransactionException: Could not open JPA EntityManager for transaction; nested exception is java.lang.NoSuchMethodError: org.hibernate.Session.getFlushMode()Lorg/hibernate/FlushMode;
    at org.springframework.orm.jpa.JpaTransactionManager.doBegin(JpaTransactionManager.java:431)
    at org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:373)
    at org.springframework.test.context.transaction.TransactionContext.startTransaction(TransactionContext.java:98)
    at org.springframework.test.context.transaction.TransactionalTestExecutionListener.beforeTestMethod(TransactionalTestExecutionListener.java:200)
    at org.springframework.test.context.TestContextManager.beforeTestMethod(TestContextManager.java:265)
    at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:74)
    at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
    at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86)
    at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:254)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:89)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
    at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:193)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:119)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:42)
    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:234)
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:74)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
Caused by: java.lang.NoSuchMethodError: org.hibernate.Session.getFlushMode()Lorg/hibernate/FlushMode;
    at org.springframework.orm.jpa.vendor.HibernateJpaDialect.prepareFlushMode(HibernateJpaDialect.java:187)
    at org.springframework.orm.jpa.vendor.HibernateJpaDialect.beginTransaction(HibernateJpaDialect.java:173)
    at org.springframework.orm.jpa.JpaTransactionManager.doBegin(JpaTransactionManager.java:380)
    ... 30 more

Jun 06, 2016 12:00:38 PM org.springframework.jdbc.datasource.init.ScriptUtils executeSqlScript
INFO: Executing SQL script from class path resource [test/downs/architecture/down.sql]
Jun 06, 2016 12:00:38 PM org.springframework.jdbc.datasource.init.ScriptUtils executeSqlScript
INFO: Executed SQL script from class path resource [test/downs/architecture/down.sql] in 5 ms.

org.springframework.transaction.CannotCreateTransactionException: Could not open JPA EntityManager for transaction; nested exception is java.lang.NoSuchMethodError: org.hibernate.Session.getFlushMode()Lorg/hibernate/FlushMode;

    at org.springframework.orm.jpa.JpaTransactionManager.doBegin(JpaTransactionManager.java:431)
    at org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:373)
    at org.springframework.test.context.transaction.TransactionContext.startTransaction(TransactionContext.java:98)
    at org.springframework.test.context.transaction.TransactionalTestExecutionListener.beforeTestMethod(TransactionalTestExecutionListener.java:200)
    at org.springframework.test.context.TestContextManager.beforeTestMethod(TestContextManager.java:265)
    at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:74)
    at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
    at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86)
    at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:254)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:89)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
    at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:193)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:119)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:42)
    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:234)
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:74)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
Caused by: java.lang.NoSuchMethodError: org.hibernate.Session.getFlushMode()Lorg/hibernate/FlushMode;
    at org.springframework.orm.jpa.vendor.HibernateJpaDialect.prepareFlushMode(HibernateJpaDialect.java:187)
    at org.springframework.orm.jpa.vendor.HibernateJpaDialect.beginTransaction(HibernateJpaDialect.java:173)
    at org.springframework.orm.jpa.JpaTransactionManager.doBegin(JpaTransactionManager.java:380)
    ... 30 more

问题答案:

Hibernate 5.2中增加了支持Spring framework 4.3,其稳定版本将于下周推出。Spring
4.2仅支持Hibernate最高5.1。

看到这个:

https://jira.spring.io/browse/SPR-14334



 类似资料:
  • 我在将Vaadin与Spring应用程序集成时遇到一些问题。我的所有bean都在“rootcontext.xml”文件中。我可以通过实例化“rootcontext.xml”然后为我的一个服务类调用bean来调用bean。 我可以这样填充表,但这是调用服务类的正确方法吗?因为我有更多的表必须称之为这个。 这是我的UI类: 我的根上下文。xml文件位于目录/WEB-INF/spring/root上下文

  • 问题内容: 我已经开发了一个Spring / JPA应用程序: 服务,存储库和域层即将完成 。 该 所缺的只是层是网络层 。我正在考虑将Playframework 2.0用于Web层,但不确定是否可以 在Playframework 2.0类中注入/使用spring bean 。 这可能吗?如果可以,怎么办? 问题答案: 您可以。已针对Play 2.5.x更新: https://github.com

  • 本文向大家介绍Spring集成MyBatis框架,包括了Spring集成MyBatis框架的使用技巧和注意事项,需要的朋友参考一下 Java在写数据库查询时,我接触过四种方式: 1、纯Java代码,引用对应的数据库驱动包,自己写连接与释放逻辑(可以用连接池) 这种模式实际上性能是非常不错的,但是使用起来并不是非常方便:一是要手工为Connection做获取与释放,大量的冗余代码也容易出错;另一个是

  • 我想知道是否有将自动化测试用例与zephy de jira集成的选项。 目前,我在robot框架中有一组自动测试。同时,我在Zephyr中为jira定义了测试用例。我希望能够从Zephyr启动自动测试用例的执行,否则执行的结果将反映在Zephyr测试用例中。 谢谢你。

  • 21. 与其他Web框架集成 21.1简介 Spring Web Flow Spring Web Flow (SWF) 旨在成为管理Web应用程序页面流的最佳解决方案。 SWF与Servlet和Portlet环境中的Spring MVC和JSF等现有框架集成。 如果您有一个业务流程(或流程)将受益于会话模型而不是纯粹的请求模型,则SWF可能是解决方案。 SWF允许您将逻辑页面流作为在不同情况下可重

  • 我第一次使用Spring Boot,正在为我的应用程序设置分布式跟踪。我已经将Spring Cloud Slueth添加到我的应用程序中,当调用我的endpoint时,我可以看到生成的跨度和跟踪,但是我很难让它与Aws Sdk 2. x集成(使用Dynamo异步客户端)。我有几个关于集成的问题: 通过aws sdk跟踪http调用的最佳方式是什么。我能做到这一点的唯一方法是实现ExecutionI