2524

Spring Mvc Hibernate Encoding/Multi-line import sql

Question:

I am working on Spring MVC,

On project startup i have set database to import default sql with hibernate configuration hibernate.hbm2ddl.import_files. Data inside import.sql is encoded with UTF-8.

<blockquote>

Console Output

</blockquote> ERROR: org.hibernate.tool.hbm2ddl.SchemaExport - HHH000388: Unsuccessful: INSERT INTO menu (id, DATE_CREATED, DATE_DELETED, DATE_UPDATED, TITLE_ENG, TITLE_GEO, TITLE_RUS, ENABLED, PARENT_ID, URL, SITE_ID, USER_ID) VALUES ERROR: org.hibernate.tool.hbm2ddl.SchemaExport - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1 ERROR: org.hibernate.tool.hbm2ddl.SchemaExport - HHH000388: Unsuccessful: (1, '2015-09-10 12:00:00', NULL, NULL, 'About Us', N'ჩვენს შეს�ხებ', 'About Us', b'1', NULL, '/article/view/1', 3, 1).

Answer1:

<ol><li>

Make sure you are setting the JDBC driver to use UTF-8:

jdbc:mysql://dbname?useUnicode=true&characterEncoding=utf-8

</li> <li>

In persistence.xml, set the hibernate connection charset:

<property name="hibernate.connection.charSet" value="UTF-8"/>

</li> </ol>

If your resources/import.sql file is multi-line, add:

<property name="hibernate.hbm2ddl.import_files_sql_extractor" value="org.hibernate.tool.hbm2ddl.MultipleLinesSqlCommandExtractor" />

or for Spring Boot, in application.properties:

spring.jpa.properties.hibernate.connection.charSet=UTF-8 spring.jpa.properties.hibernate.hbm2ddl.import_files_sql_extractor=org.hibernate.tool.hbm2ddl.MultipleLinesSqlCommandExtractor

Recommend

  • Hibernate/JPA/HSQL : How to create a Dialect mapping for User Type ARRAY
  • Hibernate/JPA/HSQL : How to create a Dialect mapping for User Type ARRAY
  • DateTime compare in django template
  • Converting string to date in Crystal Reports
  • Converting string to date in Crystal Reports
  • How can I make picture resize function when uploading in CodeIgniter
  • Is it possible to set two fields as indexes on an entity in ndb?
  • SQL database problems with addressbook table design
  • Python function optional arguments - possible to add as condition?
  • How to use an EventToCommand with an editable Combobox to bind TextBoxBase.TextChanged with a comman
  • How to insert an Image in WORD after a bookmark using OpenXML
  • Eclipse: missing requirement E4 RCP patch when installing properties editor
  • Find symbol dependencies in source code [closed]
  • How to run bash commands like “npm install” on complie
  • UML diagram generator in Visual Studio 2010
  • using html data-attributes as css-variable (i.e. text-shadow)
  • Click on button in another program - FindWindow, C#
  • VSCode change debug shell to bash on windows
  • Does Apple allow the usage of sysctl.h within iOS applications?
  • Bypass multiple inheritance in Java
  • wxPython: displaying multiple widgets in same frame
  • Moving mysql files across servers
  • ImageMagick, replace semi-transparent white with opaque white
  • Cannot connect to cassandra from Spark
  • Deleting and Updating values from a cusrsor adapter
  • PHP - How to update data to MySQL when click a radio button
  • Window Size for Mac application
  • Cross-Platform Protobuf Serialization
  • Join two tables and save into third-sql
  • How to handle AllServersUnavailable Exception
  • Alternatives to the OPTIONAL fallback SPARQL pattern?
  • using conditional logic : check if record exists; if it does, update it, if not, create it
  • How to delete a row from a dynamic generate table using jquery?
  • json Serialization in asp
  • Rails 2: use form_for to build a form covering multiple objects of the same class
  • Hits per day in Google Big Query
  • FormattedException instead of throw new Exception(string.Format(…)) in .NET
  • How to stop GridView from loading again when I press back button?
  • Linking SubReports Without LinkChild/LinkMaster
  • XCode 8, some methods disappeared ? ex: layoutAttributesClass() -> AnyClass