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.
Boolean mapping issue in Hibernate + MySQL
-
22-09-2022 - |
Question
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 ;)
Solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow