postgresql - 保存实体时出现 Utf 8 问题
问题描述
我使用带有 jpa、hibernate 和 postgres 的 spring boot 2。
在我的 build.gradle 中,我有
tasks.withType(JavaCompile) {
options.compilerArgs = ["-Xlint:unchecked", "-Xlint:deprecation", "-parameters"]
options.encoding = "UTF-8"
}
我在这里发布了一些课程https://pastebin.com/WgDqZkjf
我遇到了 utf8 的问题
在调试中我看到
select
nextval ('ignar.hibernate_sequence')
Hibernate:
select
nextval ('ignar.samples_id_seq')
Hibernate:
insert
into
ignar.samplings
(available_for_test, build_date, color_id, dimension_id, machine_id, print, product_id, reception_date, remark, special_try, test_done, to_print, delay_before_doing_test, press, quantity_received, dtype, id, year)
values
(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 'TraditionalSamplings', ?, ?)
Hibernate:
insert
into
ignar.samples
(created_at, updated_at, absorption_printed, aen_remarque, certificat_include, cube, durability_printed, fresh_density, fresh_weigth, gen_remarque, label, position, sample_letter, sampling_id, sampling_year, absorption, absorption_number, coloration, coloration_number, compression, compression_number, density, draw_down, draw_down_number, durability, durability_number, granulometry, granulometry_number, organic_material, organic_material_number, scaling, scaling_number, id)
values
(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
2018-05-21 15:38:21.214 WARN 2973 --- [io-8080-exec-10] o.h.engine.jdbc.spi.SqlExceptionHelper : SQL Error: 0, SQLState: 22021
2018-05-21 15:38:21.215 ERROR 2973 --- [io-8080-exec-10] o.h.engine.jdbc.spi.SqlExceptionHelper : ERROR: invalid byte sequence for encoding "UTF8": 0x00
2018-05-21 15:38:21.215 ERROR 2973 --- [io-8080-exec-10] o.h.i.ExceptionMapperStandardImpl : HHH000346: Error during managed flush [org.hibernate.exception.DataException: could not execute statement]
解决方案
可能是您的 char 导致了问题...尝试在您的 java 文件中将其转换为 String
推荐阅读
- database - 如何从这些表中查询这些表中的全名
- apache - apache中的本地站点只是重定向到另一个本地站点
- python - Python,范围内的递归(a,b)
- ruby-on-rails - 如何使用点符号访问 Chewy 结果?
- shopify - 如何使用应用在 shopify 页面上添加内容
- f# - 在 F# 中实现 do while?
- ethereum - 在以太坊中签名和验证消息
- javascript - 如何从 Angular 6 项目向 Android 应用发送推送通知
- javascript - Angular 5 全局组件及其服务
- ios - tabBar 在嵌套的 ViewController 中减小视图的大小