i writing app going heavily use utf-8 encoding. server i'm using java servlets, , ui i'm using java servlets jsp , javascript.
so, after ignoring gibberish time, decided solve utf-8 encoding issue. while looking solution, made filter class
followed @cosoant's answer here: https://stackoverflow.com/questions/138948/how-to-get-utf-8-working-in-java-webapps
until "mysql database , tables" (excluding), because still developing <property name="hibernate.hbm2ddl.auto" value="create" />
in persistence.xml
.
understood mysql's utf8 not rest of world's utf 8, changed characterencoding in persistence.xml to: <property name="hibernate.connection.characterencoding" value="utf8mb4" />
also, following : https://mathiasbynens.be/notes/mysql-utf8mb4
link upgraded mysqlserver, , added:
[client] default-character-set = utf8mb4
[mysql] default-character-set = utf8mb4
[mysqld] character-set-client-handshake = false character-set-server = utf8mb4 collation-server = utf8mb4_unicode_ci
to mysql.cnf
. restarted mysql typing sudo service mysql restart
in terminal , made sure when go mysql command line ui , type: show variables variable_name 'character\_set\_%' or variable_name 'collation%';
this:
+--------------------------+--------------------+ | variable_name | value | +--------------------------+--------------------+ | character_set_client | utf8mb4 | | character_set_connection | utf8mb4 | | character_set_database | utf8mb4 | | character_set_filesystem | binary | | character_set_results | utf8mb4 | | character_set_server | utf8mb4 | | character_set_system | utf8 | | collation_connection | utf8mb4_unicode_ci | | collation_database | utf8mb4_unicode_ci | | collation_server | utf8mb4_unicode_ci | +--------------------------+--------------------+
is get.
switched com.mysql.jdbc_5.1.5.jar
mysql-connector-java-5.1.44-bin.jar
.
and still, above error each time try access db.
stack trace:
exception in thread "main" java.lang.exceptionininitializererror @ tests.test.main(test.java:38) caused by: org.hibernate.service.spi.serviceexception: unable create requested service [org.hibernate.engine.jdbc.env.spi.jdbcenvironment] @ org.hibernate.service.internal.abstractserviceregistryimpl.createservice(abstractserviceregistryimpl.java:271) @ org.hibernate.service.internal.abstractserviceregistryimpl.initializeservice(abstractserviceregistryimpl.java:233) @ org.hibernate.service.internal.abstractserviceregistryimpl.getservice(abstractserviceregistryimpl.java:210) @ org.hibernate.engine.jdbc.internal.jdbcservicesimpl.configure(jdbcservicesimpl.java:51) @ org.hibernate.boot.registry.internal.standardserviceregistryimpl.configureservice(standardserviceregistryimpl.java:94) @ org.hibernate.service.internal.abstractserviceregistryimpl.initializeservice(abstractserviceregistryimpl.java:242) @ org.hibernate.service.internal.abstractserviceregistryimpl.getservice(abstractserviceregistryimpl.java:210) @ org.hibernate.boot.model.process.spi.metadatabuildingprocess.handletypes(metadatabuildingprocess.java:352) @ org.hibernate.boot.model.process.spi.metadatabuildingprocess.complete(metadatabuildingprocess.java:111) @ org.hibernate.jpa.boot.internal.entitymanagerfactorybuilderimpl.metadata(entitymanagerfactorybuilderimpl.java:858) @ org.hibernate.jpa.boot.internal.entitymanagerfactorybuilderimpl.build(entitymanagerfactorybuilderimpl.java:885) @ org.hibernate.jpa.hibernatepersistenceprovider.createentitymanagerfactory(hibernatepersistenceprovider.java:58) @ javax.persistence.persistence.createentitymanagerfactory(persistence.java:55) @ javax.persistence.persistence.createentitymanagerfactory(persistence.java:39) @ utils.hibernateutil.<clinit>(hibernateutil.java:9) ... 1 more caused by: org.hibernate.exception.jdbcconnectionexception: error calling driver#connect @ org.hibernate.engine.jdbc.connections.internal.basicconnectioncreator$1$1.convert(basicconnectioncreator.java:105) @ org.hibernate.engine.jdbc.connections.internal.basicconnectioncreator.convertsqlexception(basicconnectioncreator.java:123) @ org.hibernate.engine.jdbc.connections.internal.driverconnectioncreator.makeconnection(driverconnectioncreator.java:41) @ org.hibernate.engine.jdbc.connections.internal.basicconnectioncreator.createconnection(basicconnectioncreator.java:58) @ org.hibernate.engine.jdbc.connections.internal.pooledconnections.addconnections(pooledconnections.java:123) @ org.hibernate.engine.jdbc.connections.internal.pooledconnections.<init>(pooledconnections.java:42) @ org.hibernate.engine.jdbc.connections.internal.pooledconnections.<init>(pooledconnections.java:20) @ org.hibernate.engine.jdbc.connections.internal.pooledconnections$builder.build(pooledconnections.java:161) @ org.hibernate.engine.jdbc.connections.internal.drivermanagerconnectionproviderimpl.buildpool(drivermanagerconnectionproviderimpl.java:109) @ org.hibernate.engine.jdbc.connections.internal.drivermanagerconnectionproviderimpl.configure(drivermanagerconnectionproviderimpl.java:72) @ org.hibernate.boot.registry.internal.standardserviceregistryimpl.configureservice(standardserviceregistryimpl.java:94) @ org.hibernate.service.internal.abstractserviceregistryimpl.initializeservice(abstractserviceregistryimpl.java:242) @ org.hibernate.service.internal.abstractserviceregistryimpl.getservice(abstractserviceregistryimpl.java:210) @ org.hibernate.engine.jdbc.env.internal.jdbcenvironmentinitiator.buildjdbcconnectionaccess(jdbcenvironmentinitiator.java:145) @ org.hibernate.engine.jdbc.env.internal.jdbcenvironmentinitiator.initiateservice(jdbcenvironmentinitiator.java:66) @ org.hibernate.engine.jdbc.env.internal.jdbcenvironmentinitiator.initiateservice(jdbcenvironmentinitiator.java:35) @ org.hibernate.boot.registry.internal.standardserviceregistryimpl.initiateservice(standardserviceregistryimpl.java:88) @ org.hibernate.service.internal.abstractserviceregistryimpl.createservice(abstractserviceregistryimpl.java:259) ... 15 more caused by: java.sql.sqlexception: unsupported character encoding 'utf8mb4'. @ com.mysql.jdbc.sqlerror.createsqlexception(sqlerror.java:964) @ com.mysql.jdbc.sqlerror.createsqlexception(sqlerror.java:897) @ com.mysql.jdbc.sqlerror.createsqlexception(sqlerror.java:886) @ com.mysql.jdbc.sqlerror.createsqlexception(sqlerror.java:860) @ com.mysql.jdbc.connectionpropertiesimpl.postinitialization(connectionpropertiesimpl.java:2549) @ com.mysql.jdbc.connectionpropertiesimpl.initializeproperties(connectionpropertiesimpl.java:2519) @ com.mysql.jdbc.connectionimpl.initializedriverproperties(connectionimpl.java:3140) @ com.mysql.jdbc.connectionimpl.<init>(connectionimpl.java:763) @ com.mysql.jdbc.jdbc4connection.<init>(jdbc4connection.java:47) @ sun.reflect.nativeconstructoraccessorimpl.newinstance0(native method) @ sun.reflect.nativeconstructoraccessorimpl.newinstance(nativeconstructoraccessorimpl.java:62) @ sun.reflect.d exception in thread "main" java.lang.exceptionininitializererror @ tests.test.main(test.java:38) caused by: org.hibernate.service.spi.serviceexception: unable create requested service [org.hibernate.engine.jdbc.env.spi.jdbcenvironment] @ org.hibernate.service.internal.abstractserviceregistryimpl.createservice(abstractserviceregistryimpl.java:271) @ org.hibernate.service.internal.abstractserviceregistryimpl.initializeservice(abstractserviceregistryimpl.java:233) @ org.hibernate.service.internal.abstractserviceregistryimpl.getservice(abstractserviceregistryimpl.java:210) @ org.hibernate.engine.jdbc.internal.jdbcservicesimpl.configure(jdbcservicesimpl.java:51) @ org.hibernate.boot.registry.internal.standardserviceregistryimpl.configureservice(standardserviceregistryimpl.java:94) @ org.hibernate.service.internal.abstractserviceregistryimpl.initializeservice(abstractserviceregistryimpl.java:242) @ org.hibernate.service.internal.abstractserviceregistryimpl.getservice(abstractserviceregistryimpl.java:210) @ org.hibernate.boot.model.process.spi.metadatabuildingprocess.handletypes(metadatabuildingprocess.java:352) @ org.hibernate.boot.model.process.spi.metadatabuildingprocess.complete(metadatabuildingprocess.java:111) @ org.hibernate.jpa.boot.internal.entitymanagerfactorybuilderimpl.metadata(entitymanagerfactorybuilderimpl.java:858) @ org.hibernate.jpa.boot.internal.entitymanagerfactorybuilderimpl.build(entitymanagerfactorybuilderimpl.java:885) @ org.hibernate.jpa.hibernatepersistenceprovider.createentitymanagerfactory(hibernatepersistenceprovider.java:58) @ javax.persistence.persistence.createentitymanagerfactory(persistence.java:55) @ javax.persistence.persistence.createentitymanagerfactory(persistence.java:39) @ utils.hibernateutil.<clinit>(hibernateutil.java:9) ... 1 more caused by: org.hibernate.exception.jdbcconnectionexception: error calling driver#connect @ org.hibernate.engine.jdbc.connections.internal.basicconnectioncreator$1$1.convert(basicconnectioncreator.java:105) @ org.hibernate.engine.jdbc.connections.internal.basicconnectioncreator.convertsqlexception(basicconnectioncreator.java:123) @ org.hibernate.engine.jdbc.connections.internal.driverconnectioncreator.makeconnection(driverconnectioncreator.java:41) @ org.hibernate.engine.jdbc.connections.internal.basicconnectioncreator.createconnection(basicconnectioncreator.java:58) @ org.hibernate.engine.jdbc.connections.internal.pooledconnections.addconnections(pooledconnections.java:123) @ org.hibernate.engine.jdbc.connections.internal.pooledconnections.<init>(pooledconnections.java:42) @ org.hibernate.engine.jdbc.connections.internal.pooledconnections.<init>(pooledconnections.java:20) @ org.hibernate.engine.jdbc.connections.internal.pooledconnections$builder.build(pooledconnections.java:161) @ org.hibernate.engine.jdbc.connections.internal.drivermanagerconnectionproviderimpl.buildpool(drivermanagerconnectionproviderimpl.java:109) @ org.hibernate.engine.jdbc.connections.internal.drivermanagerconnectionproviderimpl.configure(drivermanagerconnectionproviderimpl.java:72) @ org.hibernate.boot.registry.internal.standardserviceregistryimpl.configureservice(standardserviceregistryimpl.java:94) @ org.hibernate.service.internal.abstractserviceregistryimpl.initializeservice(abstractserviceregistryimpl.java:242) @ org.hibernate.service.internal.abstractserviceregistryimpl.getservice(abstractserviceregistryimpl.java:210) @ org.hibernate.engine.jdbc.env.internal.jdbcenvironmentinitiator.buildjdbcconnectionaccess(jdbcenvironmentinitiator.java:145) @ org.hibernate.engine.jdbc.env.internal.jdbcenvironmentinitiator.initiateservice(jdbcenvironmentinitiator.java:66) @ org.hibernate.engine.jdbc.env.internal.jdbcenvironmentinitiator.initiateservice(jdbcenvironmentinitiator.java:35) @ org.hibernate.boot.registry.internal.standardserviceregistryimpl.initiateservice(standardserviceregistryimpl.java:88) @ org.hibernate.service.internal.abstractserviceregistryimpl.createservice(abstractserviceregistryimpl.java:259) ... 15 more caused by: java.sql.sqlexception: unsupported character encoding 'utf8mb4'. @ com.mysql.jdbc.sqlerror.createsqlexception(sqlerror.java:964) @ com.mysql.jdbc.sqlerror.createsqlexception(sqlerror.java:897) @ com.mysql.jdbc.sqlerror.createsqlexception(sqlerror.java:886) @ com.mysql.jdbc.sqlerror.createsqlexception(sqlerror.java:860) @ com.mysql.jdbc.connectionpropertiesimpl.postinitialization(connectionpropertiesimpl.java:2549) @ com.mysql.jdbc.connectionpropertiesimpl.initializeproperties(connectionpropertiesimpl.java:2519) @ com.mysql.jdbc.connectionimpl.initializedriverproperties(connectionimpl.java:3140) @ com.mysql.jdbc.connectionimpl.<init>(connectionimpl.java:763) @ com.mysql.jdbc.jdbc4connection.<init>(jdbc4connection.java:47) @ sun.reflect.nativeconstructoraccessorimpl.newinstance0(native method) @ sun.reflect.nativeconstructoraccessorimpl.newinstance(nativeconstructoraccessorimpl.java:62) @ sun.reflect.delegatingconstructoraccessorimpl.newinstance(delegatingconstructoraccessorimpl.java:45) @ java.lang.reflect.constructor.newinstance(constructor.java:423) @ com.mysql.jdbc.util.handlenewinstance(util.java:425) @ com.mysql.jdbc.connectionimpl.getinstance(connectionimpl.java:389) @ com.mysql.jdbc.nonregisteringdriver.connect(nonregisteringdriver.java:330) @ org.hibernate.engine.jdbc.connections.internal.driverconnectioncreator.makeconnection(driverconnectioncreator.java:38) ... 30 moreelegatingconstructoraccessorimpl.newinstance(delegatingconstructoraccessorimpl.java:45) @ java.lang.reflect.constructor.newinstance(constructor.java:423) @ com.mysql.jdbc.util.handlenewinstance(util.java:425) @ com.mysql.jdbc.connectionimpl.getinstance(connectionimpl.java:389) @ com.mysql.jdbc.nonregisteringdriver.connect(nonregisteringdriver.java:330) @ org.hibernate.engine.jdbc.connections.internal.driverconnectioncreator.makeconnection(driverconnectioncreator.java:38) ... 30 more
i think got point i'm stuck.
i'd appreciate help. thanks!
try in hibernate xml configuration file:
<property name="hibernate.connection.charset">utf8mb4</property> <property name="hibernate.connection.characterencoding">utf8</property> <property name="hibernate.connection.useunicode">true</property>
also make changes connection url follows:
db.url=jdbc:mysql://localhost:3306/db_name?useunicode=true&character_set_server=utf8mb4
the above changes enough me upgrade utf8 utf8mb4 charset scheme.
as side note make 1 clarification utf8
character encoding while utf8mb4
character set mysql supports. utf8mb4 superset utf8. refer link more information: https://dev.mysql.com/doc/refman/5.5/en/charset-unicode-utf8mb4.html
Comments
Post a Comment