我在保存一个简单的模型对象时从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();
}
}
这是我从休眠中得到的错误:
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。