メンチカツには醤油でしょ!!

ITエンジニア徒然 (AWS/Java/JavaScript/Google Spreadsheets/Jenkins/Mac/外部コミュニティ・勉強会レポ)

Wildfly(JBoss)+JPA+MySQLで日本語が文字化け

最初文字コードの問題なのかと思ってたら…

d.hatena.ne.jp

さすがのきしださんです。

NativeQueryのパラメーターのバインドでも

some_field_name like concat('%', ?, '%')

みたいなことやって日本語をバインドしてもやっぱ取れません。
私はこっちの問題からキマシタ。

…で、useUnicode=true&characterEncoding=utf8を設定しようと思って、ASがWildflyだったのでstandalone.xmlのconnection-urlの後ろに足したら…

hh:mm:ss,SSS ERROR [org.jboss.as.server] (Controller Boot Thread) WFLYSRV0055: Caught exception during boot: org.jboss.as.controller.persistence.ConfigurationPersistenceException: WFLYCTL0085: Failed to parse configuration
at org.jboss.as.controller.persistence.XmlConfigurationPersister.load(XmlConfigurationPersister.java:131)
at org.jboss.as.server.ServerService.boot(ServerService.java:356)
at org.jboss.as.controller.AbstractControllerService$1.run(AbstractControllerService.java:299)
at java.lang.Thread.run(Thread.java:745)
Caused by: javax.xml.stream.XMLStreamException: com.ctc.wstx.exc.WstxUnexpectedCharException: Unexpected character '=' (code 61); expected a semi-colon after the reference for entity 'characterEncoding'
at [row,col {unknown-source}]: [139,114]
at org.jboss.as.connector.subsystems.datasources.DataSourcesExtension$DataSourceSubsystemParser.readElement(DataSourcesExtension.java:637)
at org.jboss.as.connector.subsystems.datasources.DataSourcesExtension$DataSourceSubsystemParser.readElement(DataSourcesExtension.java:200)
at org.jboss.staxmapper.XMLMapperImpl.processNested(XMLMapperImpl.java:110)
at org.jboss.staxmapper.XMLExtendedStreamReaderImpl.handleAny(XMLExtendedStreamReaderImpl.java:69)
at org.jboss.as.server.parsing.StandaloneXml_4.parseServerProfile(StandaloneXml_4.java:546)
at org.jboss.as.server.parsing.StandaloneXml_4.readServerElement(StandaloneXml_4.java:242)
at org.jboss.as.server.parsing.StandaloneXml_4.readElement(StandaloneXml_4.java:141)
at org.jboss.as.server.parsing.StandaloneXml.readElement(StandaloneXml.java:103)
at org.jboss.as.server.parsing.StandaloneXml.readElement(StandaloneXml.java:49)
at org.jboss.staxmapper.XMLMapperImpl.processNested(XMLMapperImpl.java:110)
at org.jboss.staxmapper.XMLMapperImpl.parseDocument(XMLMapperImpl.java:69)
at org.jboss.as.controller.persistence.XmlConfigurationPersister.load(XmlConfigurationPersister.java:123)
... 3 more
Caused by: com.ctc.wstx.exc.WstxUnexpectedCharException: Unexpected character '=' (code 61); expected a semi-colon after the reference for entity 'characterEncoding'
at [row,col {unknown-source}]: [139,114]
at com.ctc.wstx.sr.StreamScanner.throwUnexpectedChar(StreamScanner.java:647)
at com.ctc.wstx.sr.StreamScanner.parseEntityName(StreamScanner.java:2066)
at com.ctc.wstx.sr.StreamScanner.fullyResolveEntity(StreamScanner.java:1525)
at com.ctc.wstx.sr.BasicStreamReader.readTextSecondary(BasicStreamReader.java:4701)
at com.ctc.wstx.sr.BasicStreamReader.readCoalescedText(BasicStreamReader.java:4146)
at com.ctc.wstx.sr.BasicStreamReader.getElementText(BasicStreamReader.java:683)
at org.jboss.staxmapper.XMLExtendedStreamReaderImpl.getElementText(XMLExtendedStreamReaderImpl.java:144)
at org.jboss.as.connector.util.AbstractParser.rawElementText(AbstractParser.java:61)
at org.jboss.as.connector.subsystems.datasources.DsParser.parseDataSource_4_0(DsParser.java:1883)
at org.jboss.as.connector.subsystems.datasources.DsParser.parseDataSources(DsParser.java:222)
at org.jboss.as.connector.subsystems.datasources.DsParser.parse(DsParser.java:182)
at org.jboss.as.connector.subsystems.datasources.DataSourcesExtension$DataSourceSubsystemParser.readElement(DataSourcesExtension.java:630)
... 14 more

hh:mm:ss,SSS FATAL [org.jboss.as.server] (Controller Boot Thread) WFLYSRV0056: Server boot has failed in an unrecoverable manner; exiting. See previous messages for details.

って…出るんですよ。

これが紛らわしいエラーメッセージ

メッセージの内容が
Unexpected character '=' (code 61); expected a semi-colon after the reference for entity 'characterEncoding'
なんですけど、これだと=付近がどうのこうのと見えますよね。
しかし、=は関係なく&を&で書くのが正しい設定です。

datasource設定

<datasource jndi-name="java:jboss/datasources/myMySQLDataSource" pool-name="myMySQLDataSource" enabled="true" use-java-context="true">
<connection-url>jdbc:mysql://localhost:3306/myMySQLDataSource?useUnicode=true&amp;characterEncoding=utf8</connection-url>
<driver>mysql</driver>
<security>
<user-name>obara</user-name>
<password>pass</password>
</security>
</datasource>

こちらが参考になりましたm(_ _)m

JBoss/MySQLと接続する - きのさいと