【发布时间】:2017-01-30 14:02:26
【问题描述】:
我正在尝试使用 Spring-JPA 更新列的值,值是表情符号/表情符号。 但收到错误提示 java.sql.BatchUpdateException: Incorrect string value: '\xF0\x9F\x98\x84\xF0\x9F...' for column
这是连接网址-
jdbc.url=jdbc:mysql:localhost:3306/woo?autoReconnect=true&useUnicode=true&characterEncoding=UTF-8&connectionCollation=utf8mb4_unicode_ci&characterSetResults=UTF-8
这里是调用代码
userProfile.setAboutMeText("\uD83D\uDE04\uD83D\uDC68\u200D\u2764\uFE0F\u200D\uD83D\uDC8B\u200D\uD83D\uDC68\uD83D\uDE02\uD83D\uDE20");
这是实体
@Entity
public class UserProfile implements Serializable {
@Column(length = 1000)
private String aboutMeText;
@Id
private Long id;
public Long getId() {
return id;
}
public void seId(Long id) {
this.id = id;
}
public String getAboutMeText() {
return JsonEscape.unescapeJson(aboutMeText);
}
public void setAboutMeText(String aboutMeText) {
this.aboutMeText = JsonEscape.escapeJson(aboutMeText);
}
和
这是完整的错误:
HTTP Status 500 - Request processing failed; nested exception is org.springframework.dao.DataIntegrityViolationException: Data truncation: Data too long for column 'aboutMeText' at row 1; SQL [n/a]; nested exception is org.hibernate.exception.DataException: Data truncation: Data too long for column 'aboutMeText' at row 1</h1>
<div class="line"></div>
<p>
<b>type</b> Exception report
</p>
<pre>org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.dao.DataIntegrityViolationException: Data truncation: Data too long for column 'aboutMeText' at row 1; SQL [n/a]; nested exception is org.hibernate.exception.DataException: Data truncation: Data too long for column 'aboutMeText' at row 1
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:981)
org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:871)
javax.servlet.http.HttpServlet.service(HttpServlet.java:648)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:845)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:77)
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
我尝试并检查了有关 stackoverflow 、 stackexchange 等的各种帖子。并进行了一些更改,但仍然无法解决问题。
【问题讨论】:
-
将排序规则更改为 utf8_unicode_ci...check this 和 this
-
以前是 utf8_unicode_ci,但我遇到了同样的错误,所以将其更改为 utf8mb4_unicode_ci
-
您存储在该列中的是二进制数据吗?那么不应该是 byte[] 而不是 blob 类型的 String 吗?
-
它是普通文本、表情符号/表情符号和特殊字符的组合,例如: 5Cud83d%5Cude04%5Cud83d%5Cudc68%5Cu200d%5Cu2764%”。它的表情符号和特殊字符的编码值。
-
userProfile.setAboutMeText("\uD83D\uDE20\uD83D\uDE20\uD83D\uDE07\uD83D\uDE02\uD83D\uDE02\uD83D\uDE20\uD83D\uDE20\uD83D\uDE02\uD83D\uDE02\uD83D\uDE02\uD83D\uDE02\uD83D\uDE02\uD83D\uDE02\uD83D\uDE07\uD83D\uDE02\uD83D\uDE20\uD83D\uDE20\uD83D\uDE20\uD83D\uDE20\uD83D\uDE20\uD83D\uDE02\uD83D\uDE02\uD83D\uDE02\uD83D\uDE02\uD83D\uDE02\uD83D\uDE20\uD83D\uDE02\uD83D\uDE02\uD83D\uDE02\uD83D\uDE02\uD83D\uDE22\uD83D\uDE22\uD83D\uDE02\uD83D\uDE20\uD83D\uDE20\uD83D\uDE20\uD83D\uDE20\uD83D");
标签: spring hibernate spring-mvc jpa spring-data-jpa