我在下面有这个 user_model.java:
public class User_Model implements Serializable {
@Id @GeneratedValue
private Long id;
@ColumnTransformer(
read="AES_DECRYPT(username, 'Hf7p4u6e') USING utf8))",
write="AES_ENCRYPT(?, 'Hf7p4u6e')")
当我删除 USING utf8)
时,上面的代码可以正常工作,但是当我再次放置它时,我得到了这个错误
您的 SQL 语法有误;查看与您的 MySQL 服务器版本对应的手册,了解在 '.USING user_mo0_.UTF-8)
附近使用的正确语法。
我不想删除 utf8
,因为我将它用于韩语。
我还在我的 hibernate.xml 中设置了一个 utf8
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/mydb?UseUnicode=true&characterEncoding=utf8</property>
<property name="hibernate.connection.CharSet">utf8</property>
<property name="hibernate.connection.characterEncoding">utf8</property>
<property name="hibernate.connection.useUnicode">true</property>
但是,它仍然根本不起作用。我怎样才能让我的查询起作用?任何帮助
最佳答案
两件事:
也许您需要将“USING utf8”与 CONVERT 函数一起使用 (https://dev.mysql.com/doc/refman/5.0/en/charset-convert.html)
CONVERT(_latin1 AES_DECRYPT(用户名, 'Hf7p4u6e') 使用 utf8)
utf8 与您已创建的表无关,如果它们不是 UTF-8 格式的话。这只会强制新创建的表使用 UTF-8。现有表格保持原样。
关于java - 使用 UTF-8 查询在 hibernate 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32474168/