我正在努力让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:类型org.threeten.bp.Duration不存在异常? Threeten没有被Maven中的usertype声明所吸引,并且在usertype中它的作用并不多。
谢谢!
约翰
答案 0 :(得分:1)
在POM中删除以下依赖项后尝试。它对我有用。
<dependency>
<groupId>org.jadira.usertype</groupId>
<artifactId>usertype.extended</artifactId>
<version>3.1.0.CR2</version>
</dependency>
答案 1 :(得分:0)
这是解决此问题的方法。这些是托管环境(特别是wildfly 8)
的最小pom.xml
依赖关系
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;