【问题标题】:More convenient way for Spring data with jpa to store utf-8 strings in SQL Server使用 jpa 的 Spring 数据在 SQL Server 中存储 utf-8 字符串的更方便的方法
【发布时间】:2019-07-02 08:02:02
【问题描述】:

我正在使用 Spring Boot 和 SQL Server 开发一个项目。几乎我所有的字符串都是波斯语的,需要存储为 utf-8。但是对于每个字符串字段,我不得不在每个字符串字段上使用@Nationalized 注释来强制 jpa 将该列创建为nvarchar。否则字符串将无法正确保留。有没有更方便的方法来做到这一点?

【问题讨论】:

    标签: java spring hibernate jpa spring-data


    【解决方案1】:

    根据 Hibernate 文档,这是可能的:

    如果您的应用程序和数据库使用国有化,您可以改为 想要默认启用国有化字符数据。

    您可以通过 hibernate.use_nationalized_character_data 执行此操作 设置或通过调用 MetadataBuilder#enableGlobalNationalizedCharacterDataSupport 期间 引导程序。

    来源:https://docs.jboss.org/hibernate/orm/5.4/userguide/html_single/Hibernate_User_Guide.html#basic-nationalized

    在 Spring Boot application.properties 中你必须设置:

    spring.jpa.properties.hibernate.use_nationalized_character_data =true
    

    【讨论】:

    • 我在 application.properties 中做了这个:spring.jpa.hibernate.use_nationalized_character_data=true,但这不起作用。我应该如何在 Spring Boot 项目中启用它?
    • @NarimanEsmaielyFard 你忘了properties 之间的部分,spring.jpa。 属性 .hibernate.use_nationalized_character_data
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-04-05
    • 2018-02-22
    • 2015-02-20
    • 1970-01-01
    • 2011-04-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多