簡體   English   中英

Spring JPA Hibernate和AttributeConverter

[英]Spring JPA Hibernate and AttributeConverter

我有一個小應用程序(spring 4.0,jpa 2.1,hibernate 5.0.2),並且一直在使用“舊的” java.util.Date *類以及java.sql.Date *。 現在我想使用java.time並讀取它可以使用AttributeConverter。 不幸的是,這似乎不起作用。 當我嘗試使用時間戳讀取數據庫對象的時候(DOA具有等效的java.time.localdatetime),我得到了一個異常。 即使有注釋,似乎也沒有使用Converter。 我只有一個applicationContext.xml,沒有persistence.xml,所以我要告訴jpa在哪里使用Converter(如果注釋不夠的話)? 我怎樣才能看到AttributeConverter被jpa接走了?

預先感謝約翰。

@Converter在JPA2.1中可用。

嘗試更改依賴項配置:

    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-entitymanager</artifactId>
        <version>4.3.5.Final</version>
    </dependency>

    <dependency>
        <groupId>org.springframework.data</groupId>
        <artifactId>spring-data-jpa</artifactId>
        <version>1.7.2.RELEASE</version>
        <type>jar</type>
        <scope>compile</scope>
    </dependency>

    <dependency>
        <groupId>org.hibernate.javax.persistence</groupId>
        <artifactId>hibernate-jpa-2.1-api</artifactId>
        <version>1.0.0.Final</version>
    </dependency>

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM