简体   繁体   English

SQLException:无法使用休眠将java.util.Date强制转换为java.sql.Time

[英]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 . 我有一个对象,并使用Hibernate逆向工程向导Hibernate映射文件以及来自数据库的POJO创建了它。

In this case my table has a sql time field( reminder_time ), but hibernate generated the field as java.util.Date field . 在这种情况下,我的表具有一个sql time字段( hinter_time ),但是hibernate将该字段生成为java.util.Date field。

This is my table, 这是我的桌子

在此处输入图片说明

The mentioned field is reminder_time. 提到的字段是hinter_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中保留关键字,需要通过反引号进行转义或使用其他列名。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在Java中混合使用java.util.date和java.sql.Time - Mixing java.util.date and a java.sql.Time in Java 将 java.util.date 与 java.sql.Time 合并 - Merge java.util.date with java.sql.Time 如何将java.sql.Date和java.sql.Time合并到java.util.Date? - How to merge java.sql.Date and java.sql.Time to java.util.Date? 如何将java.util.Date对象与java.sql.Time对象组合? - How do I combine a java.util.Date object with a java.sql.Time object? 休眠-java.time.LocalDate无法转换为java.util.Date - Hibernate - java.time.LocalDate cannot be cast to java.util.Date ClassCastException:无法将java.util.Date强制转换为 - ClassCastException: java.util.Date cannot be cast to MySQL:使用Java和Hibernate的java.sql.Time数据类型返回java.sql.Date - Mysql: java.sql.Time datatype using java and hibernate returns back java.sql.Date ClassCastException:无法将java.util.Date强制转换为java.sql.Date - ClassCastException: java.util.Date cannot be cast to java.sql.Date ClassCastException:java.util.Date 不能转换为 java.time.temporal.Temporal - ClassCastException: java.util.Date cannot be cast to java.time.temporal.Temporal 尝试转换时间戳字段时,oracle.sql.timestamp 无法转换为 java.util.date - oracle.sql.timestamp cannot be cast to java.util.date when trying to convert timestamp field
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM