Hypersistence Micronaut Postgres daterange issue

147 views Asked by At

In my project I need to persist a range of dates into a Postgres database. For this I decided to use the hibernate-types-52 dependency, but when I try to persist anything I get the following error:

Can't infer the SQL type to use for an instance of com.vladmihalcea.hibernate.type.range.Range. Use setObject() with an explicit Types value to specify the type to use.

@Entity
@Table(name = "reservation")
@TypeDef(
        typeClass = PostgreSQLRangeType.class,
        defaultForType = Range.class
)
class Reservation {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @JsonIgnore
    Long id
    @Column(name = "date_range", columnDefinition = "daterange")
    Range<LocalDate> dateRange
    @Column(name = 'reservation_code')
    UUID reservationCode
}

Reservation save(String from, String to) { 
    Range<LocalDate> range = Range.closedOpen(
    LocalDate.parse(from, DateTimeFormatter.ofPattern("yyyy-MM-dd")),
    LocalDate.parse(to, DateTimeFormatter.ofPattern("yyyy-MM-dd"))
    )
    
    Reservation reservation = new Reservation(range, UUID.randomUUID())
    reservationRepository.save(reservation)
}

Any ideas what may be causing this?

0

There are 0 answers