java - Hibernate 在保存对象时生成 mysql 错误

标签 java mysql hibernate

我在保存一个简单的模型对象时从 hibernate 收到一个 mysql 错误,但似乎无法找到问题所在。我的模型类是:

@Entity (name = "match")
public class Match {

    @Id @GeneratedValue (strategy = GenerationType.AUTO)
    private int matchId;
    private int size;
    private int maxSize;

    @Temporal (TemporalType.DATE)
    private Date createDate;

        //setter & getters
 }

保存实例的方法:

@Test
public void save ()
{

    Match match = new Match ();
    match.setMaxSize(10);
    match.setSize(8);
    match.setCreateDate(new Date ());
    Session session = Hibernate.getSessionFactory().openSession();
    try 
    {
        session.beginTransaction();
        session.save(match);
        session.getTransaction().commit();
    } catch (HibernateException e) 
    {
        session.getTransaction().rollback();
        e.printStackTrace();
    }
}

这是我从 hibernate 中得到的错误:

 com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: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 'match (createDate, maxSize, size) values ('2013-06-28', 10, 8)' at line 1

我认为这可能是一个方言问题,但我不确定我是否正在为我的方言类使用 org.hibernate.dialect.MySQLDialect。

最佳答案

匹配reserved MySQL keyword .更改表的名称。

关于java - Hibernate 在保存对象时生成 mysql 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17369376/

相关文章:

java - jar 顶层内的多个入口点(主类)

java - 多线程 JMS 应用程序

java - 如何运行 for 循环来显示数组的不同元素?

php - 在表单中使用 Quill 并将数据传输到 mysql 数据库

java - 我可以在 JPA 中使用 select from derived tables 吗?

hibernate - 如何防止出现 org.hibernate.loader.MultipleBagFetchException

java - 如何在 Flutter 应用程序和它的 android/ios 代码之间建立一个发布-订阅 channel ?

php - 统计相关表Gridview中的记录

php - 将我的 RESTful API 仅限于我的应用程序

java - 虽然有 Composite Primary Key,但 Hibernate 在只有一个键唯一时报错