Jadira, Hibernate, and JSR 310 - java.lang.TypeNotPresentException: Type org.threeten.bp.Duration not present

StackOverflow https://stackoverflow.com/questions/16262896

  •  13-04-2022
  •  | 
  •  

Question

I'm trying to get Jadira, Hibernate 4, and JSR-310 working together and I'm getting a really odd exception that I can't find any info on through scanning the web.

POM elements (related to 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>

Here's my test code:

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

Application Context:

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

Does anyone have any idea why I keep getting java.lang.TypeNotPresentException: Type org.threeten.bp.Duration not present exceptions? Threeten isn't getting pulled in by the usertype declaration in Maven and there's not much out there about it's role in usertype.

Thanks!

John

Was it helpful?

Solution

Try after removing the following dependency in POM. It worked for me.

 <dependency>  
       <groupId>org.jadira.usertype</groupId>  
       <artifactId>usertype.extended</artifactId>  
       <version>3.1.0.CR2</version>  
 </dependency>  

OTHER TIPS

This is the way to solve this issue. These are the minimal pom.xml dependencies for a managed environment (specifically wildfly 8)

pom.xml dependencies:

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

After this, map each entity's temporal attributes in the following way:

@Type(type="org.jadira.usertype.dateandtime.joda.PersistentLocalDate")
private LocalDate birthday;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top