0

我试图让 Jadira、Hibernate 4 和 JSR-310 一起工作,但我遇到了一个非常奇怪的异常,我无法通过扫描网络找到任何信息。

POM 元素(与 Jadira/Joda 相关)

<dependency>
   <groupId>joda-time</groupId>
   <artifactId>joda-time</artifactId>
   <version>2.1</version>
</dependency>
<dependency>
    <groupId>org.jadira.usertype</groupId>
    <artifactId>usertype.core</artifactId>
    <version>3.1.0.CR2</version>
</dependency>
<dependency>
    <groupId>org.jadira.usertype</groupId>
    <artifactId>usertype.extended</artifactId>
    <version>3.1.0.CR2</version>
</dependency>
<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-testing</artifactId>
    <version>${hibernate.version}</version>
</dependency>
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-context-support</artifactId>
    <version>${spring.framework.version}</version>
</dependency>
<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-entitymanager</artifactId>
    <version>${hibernate.version}</version>
</dependency>

这是我的测试代码:

@Entity
@Table(name = "BUSINESS_DATES")
@BizDateValidatorI
public class BizDate {

    @Id
    @Column(name="BIZ_DATE_PK")
    private int bizDatePk = -1;

    @Column(name="BIZ_DATE")
    @Type(type="org.jadira.usertype.dateandtime.joda.jsr310.PersistentLocalDate")   
    @NotNull
    private LocalDate bizDate;

    @Column(name="BIZ_DATE_TYPE")
    @Enumerated(EnumType.STRING)
    @NotNull
    private BizDateTypeEnum bizDateTypeEnum;

    @Column(name="DATE_DESC")
    @NotBlank
    @Length(min = 5, max = 100)
    private String dateDesc;

    @Column(name="START_TIME")
    @Type(type="org.jadira.usertype.dateandtime.joda.jsr310.PersistentLocalDateTime")   
    private LocalDateTime startTime;

    @Column(name="END_TIME")
    @Type(type="org.jadira.usertype.dateandtime.joda.jsr310.PersistentLocalDateTime")   
    private LocalDateTime endTime;

<<Omitted getters/setters>>

应用环境:

<description>Application Context for Core Utilities</description>

<tx:annotation-driven transaction-manager="transactionManager" />

<context:component-scan base-package="org.jc.utils" />

<jpa:repositories base-package="org.jc.utils" />

<jdbc:embedded-database id="dataSource" type="H2">
    <jdbc:script location="classpath:/org/jc/utils/basetests/basetests.sql" />
</jdbc:embedded-database>

有谁知道为什么我不断收到 java.lang.TypeNotPresentException: Type org.threeten.bp.Duration 不存在异常?Threeten 并没有被 Maven 中的用户类型声明所吸引,而且关于它在用户类型中的作用并不多。

谢谢!

约翰

4

2 回答 2

1

在 POM 中删除以下依赖项后尝试。它对我有用。

 <dependency>  
       <groupId>org.jadira.usertype</groupId>  
       <artifactId>usertype.extended</artifactId>  
       <version>3.1.0.CR2</version>  
 </dependency>  
于 2013-05-02T13:56:16.857 回答
0

这是解决此问题的方法。这些是pom.xml托管环境(特别是 Wildfly 8)的最小依赖项

pom.xml依赖项:

<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-annotations</artifactId>
    <version>3.5.6-Final</version>
    <scope>provided</scope>
</dependency>
<dependency>
    <groupId>org.jadira.usertype</groupId>
    <artifactId>usertype.core</artifactId>
    <version>3.2.0.GA</version>
</dependency>
<dependency>
    <groupId>joda-time</groupId>
    <artifactId>joda-time</artifactId>
    <version>2.1</version>
</dependency>

在此之后,按以下方式映射每个实体的时间属性:

@Type(type="org.jadira.usertype.dateandtime.joda.PersistentLocalDate")
private LocalDate birthday;
于 2014-06-23T04:58:38.657 回答