简体   繁体   中英

SQLException: java.util.Date cannot be cast to java.sql.Time using hibernate

I have a object and I created it by using Hibernate Reverse Engineering Wizard and Hibernate Mapping Files and POJOs From Database .

In this case my table has a sql time field( reminder_time ), but hibernate generated the field as java.util.Date field .

This is my table,

在此处输入图片说明

The mentioned field is reminder_time.

This is my object,

import java.util.Date;


public class Reminder  implements java.io.Serializable {


     private Integer idreminder;
     private Patient patient;
     private String remindAbout;
     private Date reminderTime;
     private Date reminderDate;
     private boolean active;
     private boolean repeat;
     private Date dateCreated;
     private Date lastUpdated;

    public Reminder() {
    }


    public Reminder(Patient patient, String remindAbout, Date reminderTime, Date reminderDate, boolean active, boolean repeat, Date lastUpdated) {
        this.patient = patient;
        this.remindAbout = remindAbout;
        this.reminderTime = reminderTime;
        this.reminderDate = reminderDate;
        this.active = active;
        this.repeat = repeat;
        this.lastUpdated = lastUpdated;
    }
    public Reminder(Patient patient, String remindAbout, Date reminderTime, Date reminderDate, boolean active, boolean repeat, Date dateCreated, Date lastUpdated) {
       this.patient = patient;
       this.remindAbout = remindAbout;
       this.reminderTime = reminderTime;
       this.reminderDate = reminderDate;
       this.active = active;
       this.repeat = repeat;
       this.dateCreated = dateCreated;
       this.lastUpdated = lastUpdated;
    }

    public Integer getIdreminder() {
        return this.idreminder;
    }

    public void setIdreminder(Integer idreminder) {
        this.idreminder = idreminder;
    }
    public Patient getPatient() {
        return this.patient;
    }

    public void setPatient(Patient patient) {
        this.patient = patient;
    }
    public String getRemindAbout() {
        return this.remindAbout;
    }

    public void setRemindAbout(String remindAbout) {
        this.remindAbout = remindAbout;
    }
    public Date getReminderTime() {
        return this.reminderTime;
    }

    public void setReminderTime(Date reminderTime) {
        this.reminderTime = reminderTime;
    }
    public Date getReminderDate() {
        return this.reminderDate;
    }

    public void setReminderDate(Date reminderDate) {
        this.reminderDate = reminderDate;
    }
    public boolean isActive() {
        return this.active;
    }

    public void setActive(boolean active) {
        this.active = active;
    }
    public boolean isRepeat() {
        return this.repeat;
    }

    public void setRepeat(boolean repeat) {
        this.repeat = repeat;
    }
    public Date getDateCreated() {
        return this.dateCreated;
    }

    public void setDateCreated(Date dateCreated) {
        this.dateCreated = dateCreated;
    }
    public Date getLastUpdated() {
        return this.lastUpdated;
    }

    public void setLastUpdated(Date lastUpdated) {
        this.lastUpdated = lastUpdated;
    }
}

When I tried to save some data in to this table using above object, I got following exception,

Oct 06, 2016 4:40:06 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'repeat, date_created, last_updated) values (3, 'Taking medicine', '15:30:18', '2' at line 1
org.hibernate.exception.SQLGrammarException: could not execute statement

Have any ideas about this ?

repeatMySQL中保留关键字,需要通过反引号进行转义或使用其他列名。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM