简体   繁体   中英

Hibernate generating mysql error when saving object

I getting a mysql error from hibernate when saving a simple model object but can't seem to find what the problem is. My model class is:

@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
 }

The method that saves instance:

@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();
    }
}

This is the error I'm getting from 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

I think this might be a dialect problem but I'm not sure I am using org.hibernate.dialect.MySQLDialect for my dialect class.

match is a reserved MySQL keyword . Change the name of your table.

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