3

I know there are plenty of topics on this matter, but still, I couldn't solve my problem.

This is entity class:

@Entity
@Table(name = "messages")
public class Message
{
....
@Column(name = "read", nullable = false, columnDefinition = "TINYINT(1)")
private boolean read;
....
public boolean isRead()
{
    return read;
}

public void setRead(boolean read)
{
this.read = read;
}

In messages MySQL table, read column is typed as tinyint(1). Before saving object to table I set setRead(true). When I'm saving object through Hibernate (save()) I get following error:

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 
'read, senderId, title) values ('ujhjg', 1, 1, 'W pustyni i w puszczy')'

I use jdbc.dialect=org.hibernate.dialect.MySQL5InnoDBDialect and tried few ways to solve my problem by changing annotations for boolean field, but none of them worked.

What's wrong with my mapping and how I can make it work?

Thanks for any help and your time ;)

1 Answer 1

7

The word read is one of MySQLs reserved keywords. Check the table on MySQL 5.0 Manual - 9.3. Reserved Words. Use a different name to avoid such situations.

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

1 Comment

The simpler answer I get to my questions, the more stupid I think I am :D Looks like you saved me a lot of time and stress. Cheers!

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.