1

In our project, We are using JPA 2.1, hibernate 5.1, Spring 2.4.6, hsqldb 2.3.2. We are having a problem with our hsql query and it gives us error for localdatetime conversion. This is the error : incompatible data type in conversion: from SQL type TIMESTAMP to [B, value: instance of org.hsqldb.types.TimestampData. Here is the full stacktrace: http://pastebin.com/bhGGpvNS

package calendar.model;

import java.io.Serializable;
import java.time.LocalDateTime;

import javax.persistence.Basic;
import javax.persistence.Convert;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;

import calendar.converter.LocalDateTimeAttributeConverter;

@Entity
@Table(name = "Event")
public class Event implements Serializable {

    private static final long serialVersionUID = 1L;

    private Integer eventId;
    private Integer creatorAccountId;
    private String eventName;
    private String eventStreetAddress;
    private String eventCity;
    private String eventState;

    @Convert(converter = LocalDateTimeAttributeConverter.class)
    private LocalDateTime eventTime;

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    public Integer getEventId() {
        return eventId;
    }

    public void setEventId(Integer eventId) {
        this.eventId = eventId;
    }

    @Basic(optional = false)
    public Integer getCreatorAccountId() {
        return creatorAccountId;
    }

    public void setCreatorAccountId(Integer creatorAccountId) {
        this.creatorAccountId = creatorAccountId;
    }

    @Basic(optional = false)
    public String getEventName() {
        return eventName;
    }

    public void setEventName(String eventName) {
        this.eventName = eventName;
    }

    @Basic(optional = false)
    public String getEventStreetAddress() {
        return eventStreetAddress;
    }

    public void setEventStreetAddress(String eventStreetAddress) {
        this.eventStreetAddress = eventStreetAddress;
    }

    @Basic(optional = false)
    public String getEventCity() {
        return eventCity;
    }

    public void setEventCity(String eventCity) {
        this.eventCity = eventCity;
    }

    @Basic(optional = false)
    public String getEventState() {
        return eventState;
    }

    public void setEventState(String eventState) {
        this.eventState = eventState;
    }

    @Basic(optional = false)
    public LocalDateTime getEventTime() {
        return eventTime;
    }

    public void setEventTime(LocalDateTime eventTime) {
        this.eventTime = eventTime;
    }

    public Event(){}

    public Event(Integer accountId, String name,String streetAddress, String city, String state, LocalDateTime time)
    {
        this.creatorAccountId = accountId;
        this.eventName = name;
        this.eventCity = city;
        this.eventState = state;
        this.eventStreetAddress = streetAddress;
        this.eventTime = time;
    }

    public int compareTo(Event o) {
        // TODO Auto-generated method stub
        return this.getEventTime().compareTo(o.getEventTime());
    }

}
Vandan Patel
  • 1,012
  • 1
  • 12
  • 23

2 Answers2

5

I am not sure that Java 8 Date Time support has been added to the Hibernate core module yet. At the current time, I believe that you need to also add the following dependency to your project:

<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-java8</artifactId>
    <version>5.1.0.Final</version>
</dependency>

The above should remove the need to write your own AttributeConverters for java 8 Date/Time classes.

Alan Hay
  • 22,665
  • 4
  • 56
  • 110
0

Hibernate doesn't support the LocalDateTime class. I suggest you either use joda or the built-in Java date/calendar matrix with Date.from() and friends.

Community
  • 1
  • 1
hd1
  • 33,938
  • 5
  • 80
  • 91