如何通过休眠注释映射模型 class 中的布尔字段

how to map boolean fields in model class through hibernate annotations

如何通过休眠注释在 java 模型 class 中添加布尔字段。

我正在这样做,它显示错误

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 'Like bit' at line 2

我的代码:

@Column(name="Like")
private boolean like;

@Column(name="Dislike")
private boolean dislike;

@Column(name="Flag")
private boolean flag;

事实上,您的问题是您在实体中使用了 Like 作为列名称,因此 Hibernate 将尝试将此列映射到名称 Like,同时它是保留的SQL 中的关键字,这就是出现异常的原因:

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 'Like bit' at line 2

您在这里可以做的是使用不同的列名称或转义该名称。

更多细节和转义解决方案你可以查看: