Spring Data(Spring Boot)和Joda Time字段映射问题 [英] Issue with Spring Data (Spring Boot) and Joda Time field mapping

查看:170
本文介绍了Spring Data(Spring Boot)和Joda Time字段映射问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些带有Joda DateTime字段的实体. 尝试启动应用程序时,出现以下错误:

I have some entities with Joda DateTime fields. When trying to start the application, I get the following error:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: org.hibernate.engine.spi.SessionFactoryImplementor.getProperties()Ljava/util/Map;
[...]
Caused by: java.lang.NoSuchMethodError: org.hibernate.engine.spi.SessionFactoryImplementor.getProperties()Ljava/util/Map;
    at org.jadira.usertype.spi.shared.AbstractUserTypeHibernateIntegrator.integrate(AbstractUserTypeHibernateIntegrator.java:192) ~[usertype.spi-6.0.1.GA.jar:na]
    at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:280) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final]
    at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:444) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final]
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:879) ~[hibernate-entitymanager-5.0.11.Final.jar:5.0.11.Final]

我试图放

spring.jpa.properties.jadira.usertype.autoRegisterUserTypes=true

在application.properties中,它不起作用.因此,我将Hibernate批注添加到了我的实体类中:

in the application.properties and it didn't work. So I added the Hibernate annotation into my entity class:

@Type(type="org.jadira.usertype.dateandtime.joda.PersistentDateTime")
    private DateTime from;

它不起作用.

我的pom.xml(部分):

My pom.xml (partial):

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>
    <dependency>
        <groupId>joda-time</groupId>
        <artifactId>joda-time</artifactId>
    </dependency>
    <dependency>
        <groupId>org.jadira.usertype</groupId>
        <artifactId>usertype.core</artifactId>
        <version>6.0.1.GA</version>
    </dependency>

    <!-- Jackson json data bind -->
    <dependency>
        <groupId>com.fasterxml.jackson.jaxrs</groupId>
        <artifactId>jackson-jaxrs-json-provider</artifactId>
    </dependency>
    <dependency>
        <groupId>com.fasterxml.jackson.datatype</groupId>
        <artifactId>jackson-datatype-joda</artifactId>
    </dependency>

我还尝试了Jadira usertype.core 6.0.0.GA,5.0.0.GA和4.0.0.GA,但没有任何变化.我该如何解决?

I also tried Jadira usertype.core 6.0.0.GA, 5.0.0.GA and 4.0.0.GA but nothing changes. How can I fix that?

====================编辑 调试使我进入类AbstractUserTypeHibernateIntegrator

====================EDIT Debugging led me to line 192 of the class AbstractUserTypeHibernateIntegrator

 String isEnabled = (String)sessionFactory.getProperties().get("jadira.usertype.autoRegisterUserTypes");

我的调试器说分配给isEnabled的值是"true".但是,执行跳转到finally子句:ConfigurationHelper.setCurrentSessionFactory((SessionFactory)null)

My debugger says the value assigned to isEnabled is the "true". However, the execution jumps to the finally clause: ConfigurationHelper.setCurrentSessionFactory((SessionFactory)null)

推荐答案

SessionFactoryImplementor.getProperties()的签名在5.2中更改为返回Map而不是Properties.如果休眠版本低于此版本,则会导致NoSuchMethodError.并且请确保使用与Hibernate 5.2兼容的最新jadira jar

The signature of SessionFactoryImplementor.getProperties() changed in 5.2 to return Map rather than Properties. This leads to a NoSuchMethodError if hibernate version is lower than that. And also make sure to use latest jadira jar which is compatible with Hibernate 5.2

在您的pom.xml中添加这些依赖项

Add these dependencies in your pom.xml

<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-core</artifactId>
    <version>5.2.0.Final</version>
</dependency>

<dependency>
    <groupId>org.jadira.usertype</groupId>
    <artifactId>usertype.core</artifactId>
    <version>6.0.1.GA</version>
</dependency>

这篇关于Spring Data(Spring Boot)和Joda Time字段映射问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆