2015-02-12 138 views
0

我有一个小应用程序(春季4.0,jpa 2.1,休眠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拾取的呢?Spring JPA休眠和AttributeConverter

在此先感谢, 约翰。

+0

能否请您复制和粘贴的例外呢?分析问题可能会有帮助。 – wypieprz 2015-02-12 23:04:57

回答

0

@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>