[keycloak-user] JDBC Database issue when migrating from v3.4.3.Final to v4.1.0
Tomás García
tomas at intrahouse.com
Thu Jul 26 10:51:32 EDT 2018
Ok, I found the issue.
It's a misconfiguration one. If this happens to you:
<connection-url>jdbc:mysql://localhost:3306/databasename?useUnicode=true&characterEncoding=utf8</connection-url>
, change that utf8 to UTF-8 and the problem is gone.
Not sure why it didn't affect me in previous versions, but now it works.
On Thu, Jul 26, 2018 at 1:41 PM Tomás García <tomas at intrahouse.com> wrote:
> Hi,
>
> I was in the process of upgrading our instance of v3.4.3.Final to
> v4.1.0.Final. but the migration model manager from Keycloak crashes. Here's
> the stack trace:
>
> aused by: java.lang.RuntimeException: RESTEASY003325: Failed to construct
> public
> org.keycloak.services.resources.KeycloakApplication(javax.servlet.ServletContext,org.jboss.resteasy.core.Dispatcher)
> at
> org.jboss.resteasy.core.ConstructorInjectorImpl.construct(ConstructorInjectorImpl.java:162)
> at
> org.jboss.resteasy.spi.ResteasyProviderFactory.createProviderInstance(ResteasyProviderFactory.java:2298)
> at
> org.jboss.resteasy.spi.ResteasyDeployment.createApplication(ResteasyDeployment.java:340)
> at
> org.jboss.resteasy.spi.ResteasyDeployment.start(ResteasyDeployment.java:253)
> at
> org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.init(ServletContainerDispatcher.java:120)
> at
> org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.init(HttpServletDispatcher.java:36)
> at
> io.undertow.servlet.core.LifecyleInterceptorInvocation.proceed(LifecyleInterceptorInvocation.java:117)
> at
> org.wildfly.extension.undertow.security.RunAsLifecycleInterceptor.init(RunAsLifecycleInterceptor.java:78)
> at
> io.undertow.servlet.core.LifecyleInterceptorInvocation.proceed(LifecyleInterceptorInvocation.java:103)
> at
> io.undertow.servlet.core.ManagedServlet$DefaultInstanceStrategy.start(ManagedServlet.java:250)
> at
> io.undertow.servlet.core.ManagedServlet.createServlet(ManagedServlet.java:133)
> at
> io.undertow.servlet.core.DeploymentManagerImpl$2.call(DeploymentManagerImpl.java:565)
> at
> io.undertow.servlet.core.DeploymentManagerImpl$2.call(DeploymentManagerImpl.java:536)
> at
> io.undertow.servlet.core.ServletRequestContextThreadSetupAction$1.call(ServletRequestContextThreadSetupAction.java:42)
> at
> io.undertow.servlet.core.ContextClassLoaderSetupAction$1.call(ContextClassLoaderSetupAction.java:43)
> at
> org.wildfly.extension.undertow.security.SecurityContextThreadSetupAction.lambda$create$0(SecurityContextThreadSetupAction.java:105)
> at
> org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1508)
> at
> org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1508)
> at
> org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1508)
> at
> org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1508)
> at
> io.undertow.servlet.core.DeploymentManagerImpl.start(DeploymentManagerImpl.java:578)
> at
> org.wildfly.extension.undertow.deployment.UndertowDeploymentService.startContext(UndertowDeploymentService.java:100)
> at
> org.wildfly.extension.undertow.deployment.UndertowDeploymentService$1.run(UndertowDeploymentService.java:81)
> ... 6 more
> Caused by: org.hibernate.exception.GenericJDBCException: Could not read
> entity state from ResultSet :
> EntityKey[org.keycloak.models.jpa.entities.RealmAttributeEntity#component[name,realm]{name=_browser_header.contentSecurityPolicy,
> realm=org.keycloak.models.jpa.entities.RealmEntity#master}]
> at
> org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:47)
> at
> org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:111)
> at
> org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:97)
> at
> org.hibernate.loader.plan.exec.process.internal.EntityReferenceInitializerImpl.loadFromResultSet(EntityReferenceInitializerImpl.java:320)
> at
> org.hibernate.loader.plan.exec.process.internal.EntityReferenceInitializerImpl.hydrateEntityState(EntityReferenceInitializerImpl.java:233)
> at
> org.hibernate.loader.plan.exec.process.internal.AbstractRowReader.readRow(AbstractRowReader.java:103)
> at
> org.hibernate.loader.plan.exec.process.internal.ResultSetProcessorImpl.extractResults(ResultSetProcessorImpl.java:122)
> at
> org.hibernate.loader.plan.exec.internal.AbstractLoadPlanBasedLoader.executeLoad(AbstractLoadPlanBasedLoader.java:122)
> at
> org.hibernate.loader.plan.exec.internal.AbstractLoadPlanBasedLoader.executeLoad(AbstractLoadPlanBasedLoader.java:86)
> at
> org.hibernate.loader.collection.plan.AbstractLoadPlanBasedCollectionInitializer.initialize(AbstractLoadPlanBasedCollectionInitializer.java:88)
> at
> org.hibernate.persister.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:688)
> at
> org.hibernate.event.internal.DefaultInitializeCollectionEventListener.onInitializeCollection(DefaultInitializeCollectionEventListener.java:75)
> at
> org.hibernate.internal.SessionImpl.initializeCollection(SessionImpl.java:2004)
> at
> org.hibernate.collection.internal.AbstractPersistentCollection$4.doWork(AbstractPersistentCollection.java:567)
> at
> org.hibernate.collection.internal.AbstractPersistentCollection.withTemporarySessionIfNeeded(AbstractPersistentCollection.java:249)
> at
> org.hibernate.collection.internal.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:563)
> at
> org.hibernate.collection.internal.AbstractPersistentCollection.read(AbstractPersistentCollection.java:132)
> at
> org.hibernate.collection.internal.PersistentBag.iterator(PersistentBag.java:277)
> at
> org.keycloak.models.jpa.RealmAdapter.getAttribute(RealmAdapter.java:209)
> at
> org.keycloak.models.jpa.RealmAdapter.getDisplayName(RealmAdapter.java:79)
> at
> org.keycloak.models.cache.infinispan.entities.CachedRealm.<init>(CachedRealm.java:157)
> at
> org.keycloak.models.cache.infinispan.RealmCacheSession.getRealm(RealmCacheSession.java:399)
> at
> org.keycloak.models.jpa.JpaRealmProvider.getRealms(JpaRealmProvider.java:102)
> at
> org.keycloak.models.cache.infinispan.RealmCacheSession.getRealms(RealmCacheSession.java:459)
> at
> org.keycloak.migration.migrators.MigrateTo3_4_1.migrate(MigrateTo3_4_1.java:40)
> at
> org.keycloak.migration.MigrationModelManager.migrate(MigrationModelManager.java:94)
> at
> org.keycloak.services.resources.KeycloakApplication.migrateModel(KeycloakApplication.java:245)
> at
> org.keycloak.services.resources.KeycloakApplication.migrateAndBootstrap(KeycloakApplication.java:186)
> at
> org.keycloak.services.resources.KeycloakApplication$1.run(KeycloakApplication.java:145)
> at
> org.keycloak.models.utils.KeycloakModelUtils.runJobInTransaction(KeycloakModelUtils.java:227)
> at
> org.keycloak.services.resources.KeycloakApplication.<init>(KeycloakApplication.java:136)
> at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native
> Method)
> at
> sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
> at
> sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
> at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
> at
> org.jboss.resteasy.core.ConstructorInjectorImpl.construct(ConstructorInjectorImpl.java:150)
> ... 28 more
> Caused by: java.sql.SQLException: Can not call getNString() when field's
> charset isn't UTF-8
> at com.mysql.jdbc.JDBC4ResultSet.getNString(JDBC4ResultSet.java:212)
> at com.mysql.jdbc.JDBC4ResultSet.getNString(JDBC4ResultSet.java:232)
> at
> org.jboss.jca.adapters.jdbc.WrappedResultSet.getNString(WrappedResultSet.java:4634)
> at
> org.hibernate.type.descriptor.sql.NVarcharTypeDescriptor$2.doExtract(NVarcharTypeDescriptor.java:62)
> at
> org.hibernate.type.descriptor.sql.BasicExtractor.extract(BasicExtractor.java:47)
> at
> org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:235)
> at
> org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:231)
> at
> org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:222)
> at
> org.hibernate.type.AbstractStandardBasicType.hydrate(AbstractStandardBasicType.java:296)
> at
> org.hibernate.persister.entity.AbstractEntityPersister.hydrate(AbstractEntityPersister.java:2840)
> at
> org.hibernate.loader.plan.exec.process.internal.EntityReferenceInitializerImpl.loadFromResultSet(EntityReferenceInitializerImpl.java:305)
> ... 60 more
>
> I don't quite get why this is happening since the very same code being run
> here should be running in v3.4.3 (at
> org.keycloak.migration.migrators.MigrateTo3_4_1.migrate(MigrateTo3_4_1.java:40))
> which works fine in that version.
>
> I'm using a v5.5 MariaDB database with a 5.5 MySQL JDBC Connector. The
> same libraries I used in v3.4.3 were installed into the v4.1.0 instance, so
> no change in configuration.
>
> All the tables / columns are using UTF-8 with utf8_unicode_ci collation:
> > SHOW FULL COLUMNS FROM REALM_ATTRIBUTE;
>
> +----------+--------------+-----------------+------+-----+---------+-------+---------------------------------+---------+
> | Field | Type | Collation | Null | Key | Default | Extra
> | Privileges | Comment |
>
> +----------+--------------+-----------------+------+-----+---------+-------+---------------------------------+---------+
> | NAME | varchar(255) | utf8_unicode_ci | NO | PRI | NULL |
> | select,insert,update,references | |
> | VALUE | varchar(255) | utf8_unicode_ci | YES | | NULL |
> | select,insert,update,references | |
> | REALM_ID | varchar(36) | utf8_unicode_ci | NO | PRI | NULL |
> | select,insert,update,references | |
>
> +----------+--------------+-----------------+------+-----+---------+-------+---------------------------------+---------+
>
> The database configuration is similar to this one:
>
> <connection-url>jdbc:mysql://localhost:3306/databasename?useUnicode=true&characterEncoding=utf8</connection-url>
>
> <driver name="mysql" module="com.mysql.jdbc">
>
> <xa-datasource-class>com.mysql.jdbc.jdbc2.optional.MysqlXADataSource</xa-datasource-class>
> </driver>
>
> Thanks,
> Tomás
>
More information about the keycloak-user
mailing list