Issue description
I am migrating a project from Wildfly 8.2.1.Final to a newer version. The main objectives are to use Hibernate 5 with Java 8+ and to run on a Wildfly version compatible with java 11, for later migration (thus the problem arises with java 8).
We selected Wildfly 24.0.1.Final (Hibernate 5.3.20.Final), since it is the last version for which the jboss-migration-tool helps migrating the standalone.xml (WF 25 removes support for legacy stuff, so this will be a manual migration step).
We are using Mariadb 10, with the latest version of Mysql Connector 8. Same issue with version 5 of MySQL connector or with mariadb jdbc driver.
The issue arises when migrating non-XA datasources (XA datasources work properly). Upon EAR deployement, Wildfly keeps warning me "No DataBase Selected" when mapping each entity (see log) and then returning an error when the database is queried.
- as suggested by others, I checked that connection-url ends with the proper schema name.
- Testing the connection to the database is OK.
- when specifying the datasource as XA, it works properly (see extract of standalone.xml)
- on wildfly 8, both the XA and non-XA datasources behave properly.
- I tried specifying again the default schema (voting_db) with the hibernate property hibernate.default_schema; I get now get an error for both XA and non-XA datasources, so it does not seem a good idea (the error is however different).
- I tried downgrading to a 2.0 version of persistence.XML
Upon Wildfly start, I get the following warning:
WARN [org.jboss.as.connector.subsystems.datasources.AbstractDataSourceService$AS7DataSourceDeployer] IJ020020: Connection Properties for DataSource: 'java:jboss/datasources/votingDS' is empty, try to use driver-class: 'com.mysql.cj.jdbc.Driver' and connection-url: 'jdbc:mysql://localhost:3306/voting_db' to connect database
So I checked the standalone.xml syntax upon a datasource added via the Wildfly management interface, without finding anything wrong. And the next log message is to inform that the datasource was properly bound. A hint to something wrong, though ?
What I am missing ? I have been trying several days, searching the Web ..
Non XA datasource specification in standalone.xml (simplified)
This is the specification generating an error
<subsystem xmlns="urn:jboss:domain:datasources:6.0">
<datasources>
<datasource jndi-name="java:jboss/datasources/votingDS" pool-name="votingDS" enabled="true" use-java-context="true" use-ccm="false">
<connection-url>jdbc:mysql://localhost:3306/voting_db</connection-url>
<driver-class>com.mysql.cj.jdbc.Driver</driver-class>
<driver>mysql</driver>
<security>
<user-name>user</user-name>
<password>passwd</password>
</security>
<validation>
<valid-connection-checker class-name="org.jboss.jca.adapters.jdbc.extensions.mysql.MySQLValidConnectionChecker"/>
<validate-on-match>false</validate-on-match>
<background-validation>true</background-validation>
<background-validation-millis>600000</background-validation-millis>
<exception-sorter class-name="org.jboss.jca.adapters.jdbc.extensions.mysql.MySQLExceptionSorter"/>
</validation>
</datasource>
<drivers>
<driver name="mysql" module="com.mysql">
<datasource-class>com.mysql.cj.jdbc.MysqlDataSource</datasource-class>
</driver>
</drivers>
</datasources>
</subsystem>
XA datasource specification in standalone.xml (simplified)
This is the specification working properly.
<subsystem xmlns="urn:jboss:domain:datasources:6.0">
<datasources>
<xa-datasource jndi-name="java:jboss/datasources/votingDS" pool-name="votingDS" enabled="true" use-ccm="true">
<xa-datasource-property name="ServerName">
localhost
</xa-datasource-property>
<xa-datasource-property name="Port">
3306
</xa-datasource-property>
<xa-datasource-property name="DatabaseName">
voting_db
</xa-datasource-property>
<driver>mysql</driver>
<security>
<user-name>user</user-name>
<password>password</password>
</security>
<validation>
<valid-connection-checker class-name="org.jboss.jca.adapters.jdbc.extensions.mysql.MySQLValidConnectionChecker"/>
<validate-on-match>false</validate-on-match>
<background-validation>true</background-validation>
<background-validation-millis>600000</background-validation-millis>
<exception-sorter class-name="org.jboss.jca.adapters.jdbc.extensions.mysql.MySQLExceptionSorter"/>
</validation>
</xa-datasource>
<drivers>
<driver name="mysql" module="com.mysql">
<driver-class>com.mysql.cj.jdbc.Driver</driver-class>
<xa-datasource-class>com.mysql.cj.jdbc.MysqlXADataSource</xa-datasource-class>
</driver>
</drivers>
</datasources>
</subsystem>
Simplified persistence.xml
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence
http://xmlns.jcp.org/xml/ns/persistence/persistence_2_2.xsd"
version="2.2">
<persistence-unit name="votingDS" transaction-type="JTA">
<jta-data-source>java:jboss/datasources/votingDS</jta-data-source>
<properties>
<property name="hibernate.hbm2ddl.auto" value="update"/>
</properties>
</persistence-unit>
</persistence>
LOG
Here are extracts of the log. This raises several questions to me:
- is second-level caching enabled by default ? or is it activated because some entities are marked as @cacheable ?
- how important is the hibernate.properties file ?
Upon EAR Deployment
INFO [org.jboss.as.jpa] (ServerService Thread Pool -- 4) WFLYJPA0010: Starting Persistence Unit (phase 1 of 2) Service 'test.war#votingDS'
INFO [org.hibernate.validator.internal.util.Version] (MSC service thread 1-3) HV000001: Hibernate Validator 6.0.22.Final
INFO [org.hibernate.jpa.internal.util.LogHelper] (ServerService Thread Pool -- 4) HHH000204: Processing PersistenceUnitInfo [
name: votingDS
...]
INFO [org.hibernate.Version] (ServerService Thread Pool -- 4) HHH000412: Hibernate Core {5.3.20.Final}
INFO [org.hibernate.cfg.Environment] (ServerService Thread Pool -- 4) HHH000206: hibernate.properties not found
...... Instantiating Beans ..
INFO [org.hibernate.annotations.common.Version] (ServerService Thread Pool -- 4) HCANN000001: Hibernate Commons Annotations {5.0.5.Final}
INFO [io.jaegertracing.internal.JaegerTracer] (MSC service thread 1-3) No shutdown hook registered: Please call close() manually on application shutdown.
INFO [org.wildfly.microprofile.opentracing.smallrye] (MSC service thread 1-3) WFLYTRAC0001: Tracer initialized: JaegerTracer(version=Java-1.5.0, serviceName=test.war, reporter=RemoteReporter(sender=org.wildfly.extension.microprofile.opentracing.spi.sender.WildFlySender@6a47cad, closeEnqueueTimeout=1000), sampler=ConstSampler(decision=true, tags={sampler.type=const, sampler.param=true}), tags={hostname=DESKTOP-BR3QQMA, jaeger.version=Java-1.5.0, ip=10.10.0.26}, zipkinSharedRpcSpan=false, expandExceptionLogs=false, useTraceId128Bit=false)
...
INFO [org.jipijapa] (MSC service thread 1-8) JIPIORMV53020253: Second level cache enabled for test.war#votingDS
INFO [org.jboss.weld.Version] (MSC service thread 1-8) WELD-000900: 3.1.7 (SP1)
INFO [org.jboss.as.jpa] (ServerService Thread Pool -- 4) WFLYJPA0010: Starting Persistence Unit (phase 2 of 2) Service 'test.war#votingDS'
WARN [org.jboss.jca.core.connectionmanager.pool.strategy.OnePool] (ServerService Thread Pool -- 4) IJ000407: No lazy enlistment available for votingDS
INFO [org.hibernate.dialect.Dialect] (ServerService Thread Pool -- 4) HHH000400: Using dialect: org.hibernate.dialect.MySQL55Dialect
...
INFO [org.infinispan.CONTAINER] (ServerService Thread Pool -- 4) ISPN000556: Starting user marshaller 'org.wildfly.clustering.infinispan.marshalling.jboss.JBossMarshaller'
INFO [org.jboss.as.clustering.infinispan] (ServerService Thread Pool -- 4) WFLYCLINF0002: Started test.war#votingDS.vbkApplicationServer.ejb.model.campaigns.Waves cache from hibernate container
INFO [org.jboss.as.clustering.infinispan] (ServerService Thread Pool -- 4) WFLYCLINF0002: Started test.war#votingDS.vbkApplicationServer.ejb.model.campaigns.Waves-pending-puts cache from hibernate container
WARN [org.hibernate.tool.schema.internal.ExceptionHandlerLoggedImpl] (ServerService Thread Pool -- 4) GenerationTarget encountered exception accepting command : Error executing DDL "create table myEntityTabe (...) engine=InnoDB" via JDBC Statement: org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL "create table myEntityTable(.....) engine=InnoDB" via JDBC Statement
at org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase.accept(GenerationTargetToDatabase.java:67) [hibernate-core-5.3.20.Final.jar:5.3.20.Final]
at org.hibernate.tool.schema.internal.AbstractSchemaMigrator.applySqlString(AbstractSchemaMigrator.java:559) [hibernate-core-5.3.20.Final.jar:5.3.20.Final]
at org.hibernate.tool.schema.internal.AbstractSchemaMigrator.applySqlStrings(AbstractSchemaMigrator.java:504) [hibernate-core-5.3.20.Final.jar:5.3.20.Final]
at org.hibernate.tool.schema.internal.AbstractSchemaMigrator.createTable(AbstractSchemaMigrator.java:277) [hibernate-core-5.3.20.Final.jar:5.3.20.Final]
at org.hibernate.tool.schema.internal.GroupedSchemaMigratorImpl.performTablesMigration(GroupedSchemaMigratorImpl.java:71) [hibernate-core-5.3.20.Final.jar:5.3.20.Final]
at org.hibernate.tool.schema.internal.AbstractSchemaMigrator.performMigration(AbstractSchemaMigrator.java:207) [hibernate-core-5.3.20.Final.jar:5.3.20.Final]
at org.hibernate.tool.schema.internal.AbstractSchemaMigrator.doMigration(AbstractSchemaMigrator.java:114) [hibernate-core-5.3.20.Final.jar:5.3.20.Final]
at org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.performDatabaseAction(SchemaManagementToolCoordinator.java:183) [hibernate-core-5.3.20.Final.jar:5.3.20.Final]
at org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.process(SchemaManagementToolCoordinator.java:72) [hibernate-core-5.3.20.Final.jar:5.3.20.Final]
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:310) [hibernate-core-5.3.20.Final.jar:5.3.20.Final]
at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:467) [hibernate-core-5.3.20.Final.jar:5.3.20.Final]
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:1250) [hibernate-core-5.3.20.Final.jar:5.3.20.Final]
at org.jboss.as.jpa.hibernate5.TwoPhaseBootstrapImpl.build(TwoPhaseBootstrapImpl.java:44)
at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:170) [wildfly-jpa-24.0.1.Final.jar:24.0.1.Final]
at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:128) [wildfly-jpa-24.0.1.Final.jar:24.0.1.Final]
at java.security.AccessController.doPrivileged(Native Method) [rt.jar:1.8.0_171]
at org.wildfly.security.manager.WildFlySecurityManager.doChecked(WildFlySecurityManager.java:664) [wildfly-elytron-security-manager-1.16.1.Final.jar:1.16.1.Final]
at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1.run(PersistenceUnitServiceImpl.java:213) [wildfly-jpa-24.0.1.Final.jar:24.0.1.Final]
at org.jboss.threads.ContextClassLoaderSavingRunnable.run(ContextClassLoaderSavingRunnable.java:35)
at org.jboss.threads.EnhancedQueueExecutor.safeRun(EnhancedQueueExecutor.java:1990)
at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.doRunTask(EnhancedQueueExecutor.java:1486)
at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1377)
at java.lang.Thread.run(Thread.java:748) [rt.jar:1.8.0_171]
at org.jboss.threads.JBossThread.run(JBossThread.java:513)
Caused by: java.sql.SQLException: No database selected
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:129)
at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122)
at com.mysql.cj.jdbc.StatementImpl.executeInternal(StatementImpl.java:763)
at com.mysql.cj.jdbc.StatementImpl.execute(StatementImpl.java:648)
at org.jboss.jca.adapters.jdbc.WrappedStatement.execute(WrappedStatement.java:198)
at org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase.accept(GenerationTargetToDatabase.java:54) [hibernate-core-5.3.20.Final.jar:5.3.20.Final]
... 23 more
Repeating the same warning for each entity.
And Finally reaching an Error
WARN [org.hibernate.engine.jdbc.spi.SqlExceptionHelper] (default task-1) SQL Error: 1046, SQLState: 3D000
ERROR [org.hibernate.engine.jdbc.spi.SqlExceptionHelper] (default task-1) No database selected
ERROR [org.jboss.as.ejb3.invocation] (default task-1) WFLYEJB0034: Jakarta Enterprise Beans Invocation failed on component BrandBean for method public abstract vbkApplicationServer.ejb.model.Brand vbkApplicationServer.ejb.beans.local.BrandBeanLocal.findByNameCountry(java.lang.String,java.lang.String): javax.ejb.EJBException: javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: could not extract ResultSet
....
at org.wildfly.security.manager.WildFlySecurityManager.doChecked(WildFlySecurityManager.java:633) [wildfly-elytron-security-manager-1.16.1.Final.jar:1.16.1.Final]
at org.jboss.invocation.AccessCheckingInterceptor.processInvocation(AccessCheckingInterceptor.java:57)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:422)
at org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:53)
at org.jboss.as.ee.component.ViewService$View.invoke(ViewService.java:198)
at org.jboss.as.ee.component.ViewDescription$1.processInvocation(ViewDescription.java:191)
at org.jboss.as.ee.component.ProxyInvocationHandler.invoke(ProxyInvocationHandler.java:81)
...
Caused by: javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: could not extract ResultSet
at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:154) [hibernate-core-5.3.20.Final.jar:5.3.20.Final]
at org.hibernate.query.internal.AbstractProducedQuery.list(AbstractProducedQuery.java:1575) [hibernate-core-5.3.20.Final.jar:5.3.20.Final]
at org.hibernate.query.Query.getResultList(Query.java:132) [hibernate-core-5.3.20.Final.jar:5.3.20.Final]
at vbkApplicationServer.ejb.beans.BrandBean.findByNameCountry(BrandBean.java:478) [classes:]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.8.0_171]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) [rt.jar:1.8.0_171]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [rt.jar:1.8.0_171]
at java.lang.reflect.Method.invoke(Method.java:498) [rt.jar:1.8.0_171]
at org.jboss.as.ee.component.ManagedReferenceMethodInterceptor.processInvocation(ManagedReferenceMethodInterceptor.java:52)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:422)
at org.jboss.invocation.InterceptorContext$Invocation.proceed(InterceptorContext.java:509)
at org.jboss.as.weld.interceptors.Jsr299BindingsInterceptor.delegateInterception(Jsr299BindingsInterceptor.java:79)
at org.jboss.as.weld.interceptors.Jsr299BindingsInterceptor.doMethodInterception(Jsr299BindingsInterceptor.java:89)
at org.jboss.as.weld.interceptors.Jsr299BindingsInterceptor.processInvocation(Jsr299BindingsInterceptor.java:102)
at org.jboss.as.ee.component.interceptors.UserInterceptorFactory$1.processInvocation(UserInterceptorFactory.java:63)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:422)
at org.jboss.as.ejb3.component.invocationmetrics.ExecutionTimeInterceptor.processInvocation(ExecutionTimeInterceptor.java:43) [wildfly-ejb3-24.0.1.Final.jar:24.0.1.Final]
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:422)
at org.jboss.as.jpa.interceptor.SBInvocationInterceptor.processInvocation(SBInvocationInterceptor.java:47) [wildfly-jpa-24.0.1.Final.jar:24.0.1.Final]
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:422)
at org.jboss.as.ee.concurrent.ConcurrentContextInterceptor.processInvocation(ConcurrentContextInterceptor.java:45) [wildfly-ee-24.0.1.Final.jar:24.0.1.Final]
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:422)
at org.jboss.invocation.InitialInterceptor.processInvocation(InitialInterceptor.java:40)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:422)
at org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:53)
at org.jboss.as.ee.component.interceptors.ComponentDispatcherInterceptor.processInvocation(ComponentDispatcherInterceptor.java:52)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:422)
at org.jboss.as.ejb3.component.pool.PooledInstanceInterceptor.processInvocation(PooledInstanceInterceptor.java:51) [wildfly-ejb3-24.0.1.Final.jar:24.0.1.Final]
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:422)
at org.jboss.as.ejb3.component.interceptors.AdditionalSetupInterceptor.processInvocation(AdditionalSetupInterceptor.java:54) [wildfly-ejb3-24.0.1.Final.jar:24.0.1.Final]
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:422)
at org.jboss.as.ejb3.tx.CMTTxInterceptor.invokeInOurTx(CMTTxInterceptor.java:254) [wildfly-ejb3-24.0.1.Final.jar:24.0.1.Final]
... 267 more
Caused by: org.hibernate.exception.GenericJDBCException: could not extract ResultSet
at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:47) [hibernate-core-5.3.20.Final.jar:5.3.20.Final]
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:113) [hibernate-core-5.3.20.Final.jar:5.3.20.Final]
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:99) [hibernate-core-5.3.20.Final.jar:5.3.20.Final]
at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:69) [hibernate-core-5.3.20.Final.jar:5.3.20.Final]
at org.hibernate.loader.Loader.getResultSet(Loader.java:2265) [hibernate-core-5.3.20.Final.jar:5.3.20.Final]
at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:2028) [hibernate-core-5.3.20.Final.jar:5.3.20.Final]
at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1990) [hibernate-core-5.3.20.Final.jar:5.3.20.Final]
at org.hibernate.loader.Loader.doQuery(Loader.java:949) [hibernate-core-5.3.20.Final.jar:5.3.20.Final]
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:351) [hibernate-core-5.3.20.Final.jar:5.3.20.Final]
at org.hibernate.loader.Loader.doList(Loader.java:2787) [hibernate-core-5.3.20.Final.jar:5.3.20.Final]
at org.hibernate.loader.Loader.doList(Loader.java:2770) [hibernate-core-5.3.20.Final.jar:5.3.20.Final]
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2604) [hibernate-core-5.3.20.Final.jar:5.3.20.Final]
at org.hibernate.loader.Loader.list(Loader.java:2599) [hibernate-core-5.3.20.Final.jar:5.3.20.Final]
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:505) [hibernate-core-5.3.20.Final.jar:5.3.20.Final]
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:395) [hibernate-core-5.3.20.Final.jar:5.3.20.Final]
at org.hibernate.engine.query.spi.HQLQueryPlan.performList(HQLQueryPlan.java:220) [hibernate-core-5.3.20.Final.jar:5.3.20.Final]
at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1526) [hibernate-core-5.3.20.Final.jar:5.3.20.Final]
at org.hibernate.query.internal.AbstractProducedQuery.doList(AbstractProducedQuery.java:1598) [hibernate-core-5.3.20.Final.jar:5.3.20.Final]
at org.hibernate.query.internal.AbstractProducedQuery.list(AbstractProducedQuery.java:1566) [hibernate-core-5.3.20.Final.jar:5.3.20.Final]
... 297 more
Caused by: java.sql.SQLException: No database selected
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:129)
at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122)
at com.mysql.cj.jdbc.ClientPreparedStatement.executeInternal(ClientPreparedStatement.java:953)
at com.mysql.cj.jdbc.ClientPreparedStatement.executeQuery(ClientPreparedStatement.java:1009)
at org.jboss.jca.adapters.jdbc.WrappedPreparedStatement.executeQuery(WrappedPreparedStatement.java:504)
at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:60) [hibernate-core-5.3.20.Final.jar:5.3.20.Final]
... 312 more
I found the solution in https://developer.jboss.org/thread/279971
In the standalone.xml, the (non xa) entry must contain both a 'connection-url' entry and a 'connection-property name="url"' entry.
Here is the working non-xa datasource specification