2

I have hibernate entity and when I try insert it into MySQL database I get exception:

@Entity
public class Pick {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private int pid;

@OneToOne
private Match_soccer match;

@OneToOne
private Algo1 algo;

@Column(length = 100)
private String pick;

@Column(length = 5)
private double limit;
...

And when I try insert to MySQL database using hibernate:

Pick pick = new Pick();
pick.setMatch(match);
pick.setAlgo(a);
pick.setLimit(2.5);
pick.setPick("under");

PickDAO pd = new PickDAO();
pd.insertMatch(pick);

I get MySQL exception:

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 'limit, match_mid, pick) values (1, 2.5, 9358, 'under')' at line 1
2
  • Did you try changing variable name limit to some other ? Commented Aug 20, 2015 at 13:48
  • Can you show insertMatch method? Commented Aug 20, 2015 at 13:50

1 Answer 1

3

Limit is a MySQL reserved word. Rename the entity attribute to something else

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

3 Comments

This is what I'm guessing :) +1.
Yes, here was my problem :)
Honestly, this seems like a bug in the hibernate dialect for mysql. It's perfectly possible to have a column or table whose name is a reserved word, you just have to quote it properly. The dialect should be smart enough to take care of that for you.

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.