MSSQL-JPA-特殊字符的字符编码-附加'N'nativeQuery [英] MSSQL - JPA - Character encoding for Special characters - appending 'N' nativeQuery

查看:388
本文介绍了MSSQL-JPA-特殊字符的字符编码-附加'N'nativeQuery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将Spring 4.3.1与JPA 2.0结合使用,并连接到MSSQL.我正在使用JpaRepository的save方法来插入和更新数据.其中一个字段具有nvarchar,其中可以包含特殊字符,如拉丁文,中文.

I'm using Spring 4.3.1 with JPA 2.0 and connected to MSSQL. I'm using JpaRepository's save method to insert and update data. One of the fields has nvarchar which can contain special characters like Latin, Chinese.

此外,我还在applicationContext-hibernate.xml中设置了以下JPA属性.

Also, I have set below JPA properties in applicationContext-hibernate.xml.

            <prop key="hibernate.connection.CharSet">UTF-8</prop>
            <prop key="hibernate.connection.useUnicode">true</prop>
            <prop key="hibernate.connection.characterEncoding">UTF-8</prop>

当我保存数据时,所有特殊字符都保存为问号(??). 建议的解决方案是在更新查询之前添加"N"以保留插入的特殊字符.但是,我在任何地方都看不到如何在JpaRepository的save方法中附加"N".有什么建议?

When I save the data, all the special characters are saved as question marks(??). The solution suggested was to append 'N'in front of the update query to keep the special characters inserted. However, I don't see anywhere how to append 'N' in JpaRepository's save method. Any suggestions?

推荐答案

实际上不必为该字段定义byte []数组,但是

Actually don't have to define byte[] array for the field but

@Column(columnDefinition = "nvarchar(255)")
private String colName;

足够了.

这篇关于MSSQL-JPA-特殊字符的字符编码-附加'N'nativeQuery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆