0

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.

1 Answer 1

3

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.