0

保存简单模型对象时,我从休眠中收到 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();
    }
}

这是我从休眠中得到的错误:

 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 用于我的方言类。

4

1 回答 1

3

match是一个保留的 MySQL 关键字。更改表的名称。

于 2013-06-28T16:28:34.310 回答