10 Replies Latest reply on Apr 22, 2013 7:46 AM by Bartosz Majsak

    Cannot Open Connection - arquillian-persistence-extension - H2Database

    Marcos Portela Newbie

      Hi community,

       

      I've got a exception when I execute a test against a H2DATABASE. I'm using the arquillian-persistence-extension to achieve this.

      I have a two datasets written in yaml. When I execute the same test against a HSQLB database the execution is a success.

       

      My Strategy is like this:

       

      @Test

      @Cleanup(phase=TestExecutionPhase.NONE)

      @UsingDataSet({"services.yml", "settings.yml"})

      public void testCase(){

       

      }

       

      I can provide more details if necessary.

       

      I've attach the full stack trace on a file (txt).

       

      The partial stacktrace below:

       

      Caused by: org.hibernate.exception.GenericJDBCException: Could not open connection

                at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:52)

                at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:125)

                at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:110)

                at org.hibernate.engine.jdbc.internal.LogicalConnectionImpl.obtainConnection(LogicalConnectionImpl.java:304)

                at org.hibernate.engine.jdbc.internal.LogicalConnectionImpl.getConnection(LogicalConnectionImpl.java:169)

                at org.hibernate.engine.jdbc.internal.proxy.ConnectionProxyHandler.extractPhysicalConnection(ConnectionProxyHandler.java:82)

                at org.hibernate.engine.jdbc.internal.proxy.ConnectionProxyHandler.continueInvocation(ConnectionProxyHandler.java:138)

                at org.hibernate.engine.jdbc.internal.proxy.AbstractProxyHandler.invoke(AbstractProxyHandler.java:81)

                at com.sun.proxy.$Proxy209.prepareStatement(Unknown Source)

                at org.hibernate.engine.jdbc.internal.StatementPreparerImpl$5.doPrepare(StatementPreparerImpl.java:147)

                at org.hibernate.engine.jdbc.internal.StatementPreparerImpl$StatementPreparationTemplate.prepareStatement(StatementPreparerImpl.java:166)

                at org.hibernate.engine.jdbc.internal.StatementPreparerImpl.prepareQueryStatement(StatementPreparerImpl.java:145)

                at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1739)

                at org.hibernate.loader.Loader.doQuery(Loader.java:828)

                at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:289)

                at org.hibernate.loader.Loader.doList(Loader.java:2463)

                at org.hibernate.loader.Loader.doList(Loader.java:2449)

                at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2279)

                at org.hibernate.loader.Loader.list(Loader.java:2274)

                at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:470)

                at org.hibernate.hql.internal.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:355)

                at org.hibernate.engine.query.spi.HQLQueryPlan.performList(HQLQueryPlan.java:196)

                at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1115)

                at org.hibernate.internal.QueryImpl.list(QueryImpl.java:101)

                at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:252)

                ... 152 more

      Caused by: java.sql.SQLException: javax.resource.ResourceException: IJ000457: Unchecked throwable in managedConnectionReconnected() cl=org.jboss.jca.core.connectionmanager.listener.TxConnectionListener@1766a135[state=NORMAL managed connection=org.jboss.jca.adapters.jdbc.local.LocalManagedConnection@78e9177c connection handles=0 lastUse=1362407759607 trackByTx=false pool=org.jboss.jca.core.connectionmanager.pool.strategy.OnePool@f050be8 pool internal context=SemaphoreArrayListManagedConnectionPool@645f4841[pool=ExampleDS] xaResource=LocalXAResourceImpl@6b9e690d[connectionListener=1766a135 connectionManager=7178049c warned=false currentXid=null] txSync=null]

                at org.jboss.jca.adapters.jdbc.WrapperDataSource.getConnection(WrapperDataSource.java:137)

                at org.hibernate.ejb.connection.InjectedDataSourceConnectionProvider.getConnection(InjectedDataSourceConnectionProvider.java:67)

                at org.hibernate.internal.AbstractSessionImpl$NonContextualJdbcConnectionAccess.obtainConnection(AbstractSessionImpl.java:276)

                at org.hibernate.engine.jdbc.internal.LogicalConnectionImpl.obtainConnection(LogicalConnectionImpl.java:297)

                ... 173 more

      Caused by: javax.resource.ResourceException: IJ000457: Unchecked throwable in managedConnectionReconnected() cl=org.jboss.jca.core.connectionmanager.listener.TxConnectionListener@1766a135[state=NORMAL managed connection=org.jboss.jca.adapters.jdbc.local.LocalManagedConnection@78e9177c connection handles=0 lastUse=1362407759607 trackByTx=false pool=org.jboss.jca.core.connectionmanager.pool.strategy.OnePool@f050be8 pool internal context=SemaphoreArrayListManagedConnectionPool@645f4841[pool=ExampleDS] xaResource=LocalXAResourceImpl@6b9e690d[connectionListener=1766a135 connectionManager=7178049c warned=false currentXid=null] txSync=null]

                at org.jboss.jca.core.connectionmanager.AbstractConnectionManager.reconnectManagedConnection(AbstractConnectionManager.java:604)

                at org.jboss.jca.core.connectionmanager.AbstractConnectionManager.allocateConnection(AbstractConnectionManager.java:467)

                at org.jboss.jca.adapters.jdbc.WrapperDataSource.getConnection(WrapperDataSource.java:129)

                ... 176 more

      Caused by: javax.resource.ResourceException: IJ000461: Could not enlist in transaction on entering meta-aware object

                at org.jboss.jca.core.connectionmanager.tx.TxConnectionManagerImpl.managedConnectionReconnected(TxConnectionManagerImpl.java:474)

                at org.jboss.jca.core.connectionmanager.AbstractConnectionManager.reconnectManagedConnection(AbstractConnectionManager.java:599)

                ... 178 more

      Caused by: javax.transaction.SystemException: IJ000356: Failed to enlist: java.lang.Throwable: Unabled to enlist resource, see the previous warnings. tx=TransactionImple < ac, BasicAction: 0:ffff7f000101:6a8c15a8:5134a6e0:3d5 status: ActionStatus.ABORT_ONLY >

                at org.jboss.jca.core.connectionmanager.listener.TxConnectionListener$TransactionSynchronization.checkEnlisted(TxConnectionListener.java:552)

                at org.jboss.jca.core.connectionmanager.listener.TxConnectionListener.enlist(TxConnectionListener.java:282)

                at org.jboss.jca.core.connectionmanager.tx.TxConnectionManagerImpl.managedConnectionReconnected(TxConnectionManagerImpl.java:467)

                ... 179 more

        • 1. Re: Cannot Open Connection - arquillian-persistence-extension - H2Database
          Bartosz Majsak Master

          How does your test persistence.xml looks like for both cases?

          • 2. Re: Cannot Open Connection - arquillian-persistence-extension - H2Database
            Bartosz Majsak Master

            Ideally if you would share the failing test (+deps) as isolated project would be very hand to help you nailing down the problem.

            • 3. Re: Cannot Open Connection - arquillian-persistence-extension - H2Database
              Marcos Portela Newbie

              Hi Bartosz,

               

              I've prepared the arquillian-h2database-testcase. I've tryed to isolate the problem in the best way. The Link for repo:

               

              https://github.com/marcosnasp/arquillian-h2database-testcase

               

              After the execution of test case, i have obtained the stack trace showed on attached file.

               

              Thanks for help.

              • 4. Re: Cannot Open Connection - arquillian-persistence-extension - H2Database
                Bartosz Majsak Master

                The only problem is that you are pointing persistence extension to use different datasource. Default is always taken if not specified through annotation

                 

                {code:xml}<property name="defaultDataSource">java:jboss/datasources/horus-hsqldb</property>{code}

                 

                If you change to the desired one it is working as it should:

                 

                {code:xml}<property name="defaultDataSource">java:jboss/datasources/ExampleDS</property>{code}

                 

                I would suggest to create seperated profiles for each configuration and use different arquillian.xml for each.

                 

                But here's the important bit - if your persistence.xml which you are using for tests contains only one persistence unit you don't need to specify anything at all, as it will inferred from it anyway - therefore more portable.

                However I will also create defaultPersistenceUnit counterpart to the DS config, as it's anyway more portable than relying on JNDI.

                 

                Another remark, since version 1.0.0.Alpha5 dbunit properties should be in its own qualifier:

                 

                {code:xml}<extension qualifier="persistence-dbunit">

                        <property name="defaultDataSetFormat">YAML</property>

                        <property name="datatypeFactory">org.dbunit.ext.hsqldb.HsqldbDataTypeFactory</property>

                </extension>

                {code}

                 

                Have a look at the complete configuration reference

                 

                HTH

                 

                Cheers,

                Bartosz

                • 5. Re: Cannot Open Connection - arquillian-persistence-extension - H2Database
                  Marcos Portela Newbie

                  Hi Bartosz,

                   

                  I've tryed the option with multiple persistence unit. And I have not successful. 

                   

                  INFO: Unable to deduct data source from test's archive persistence.xml. Multiple persistence units defined. Please specify default data source either in 'arquillian.xml' or by using @DataSource annotation.

                   

                  persistence.xml

                   

                  <?xml version="1.0" encoding="UTF-8"?>

                  <persistence version="2.0"

                            xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

                            xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">

                   

                            <persistence-unit name="horus-h2database">

                                      <provider>org.hibernate.ejb.HibernatePersistence</provider>

                                      <jta-data-source>java:jboss/datasources/ExampleDS</jta-data-source>

                                      <properties>

                   

                                                <!-- Properties for Hibernate (default provider for JBoss AS) -->

                                                <property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect" />

                                                <property name="hibernate.hbm2ddl.auto" value="create" />

                                                <property name="hibernate.show_sql" value="false" />

                                                <property name="hibernate.format_sql" value="false" />

                   

                                       </properties>

                            </persistence-unit>

                   

                            <persistence-unit name="horus-postgres">

                                      <provider>org.hibernate.ejb.HibernatePersistence</provider>

                                      <jta-data-source>java:jboss/datasources/horusTest</jta-data-source>

                                      <properties>

                   

                                                 <!-- Properties for Hibernate (default provider for JBoss AS) -->

                                                <property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect" />

                                                <property name="hibernate.hbm2ddl.auto" value="create" />

                                                <property name="hibernate.show_sql" value="false" />

                                                <property name="hibernate.format_sql" value="false" />

                   

                                      </properties>

                            </persistence-unit>

                   

                            <persistence-unit name="horus-hsqldb">

                                      <provider>org.hibernate.ejb.HibernatePersistence</provider>

                                      <jta-data-source>java:jboss/datasources/horus-hsqldb</jta-data-source>

                                      <properties>

                   

                                                <!-- Properties for Hibernate (default provider for JBoss AS) -->

                                                <property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect" />

                                                <property name="hibernate.hbm2ddl.auto" value="create" />

                                                <property name="hibernate.show_sql" value="false" />

                                                <property name="hibernate.format_sql" value="false" />

                   

                                      </properties>

                            </persistence-unit>

                   

                  </persistence>

                   

                  arquillian.xml

                   

                  <extension qualifier="persistence-dbunit">

                            <property name="defaultDataSource">java:jboss/datasources/ExampleDS</property>

                            <property name="defaultDataSetFormat">YAML</property>

                            <property name="datatypeFactory">org.dbunit.ext.hsqldb.HsqldbDataTypeFactory</property>

                  </extension>

                   

                  @DataSource("java:jboss/datasources/ExampleDS")

                  public class ConfiguracaoRepositoryTest { }

                  • 6. Re: Cannot Open Connection - arquillian-persistence-extension - H2Database
                    Bartosz Majsak Master

                    Hi there

                     

                    arquillian.xml should look like this:

                     

                    {code:xml}<extension qualifier="persistence">

                              <property name="defaultDataSource">java:jboss/datasources/ExampleDS</property>

                    </extension>

                     

                    <extension qualifier="persistence-dbunit">

                              <property name="defaultDataSetFormat">YAML</property>

                              <property name="datatypeFactory">org.dbunit.ext.hsqldb.HsqldbDataTypeFactory</property>

                    </extension>

                    {code}

                    • 7. Re: Cannot Open Connection - arquillian-persistence-extension - H2Database
                      Marcos Portela Newbie

                      Hi,

                       

                      The log shows me this:

                       

                      13:33:37,235 INFO  [org.jboss.as.repository] (management-handler-thread - 33) JBAS014900: Content added at location /home/megatech12/desenvolvimento/jboss-as-7.1.1.Final/standalone/data/content/ea/15389fe3c3fd5fcbcaf51cf7d8f4dd9dafd3c0/content

                      13:33:37,236 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-5) JBAS015876: Starting deployment of "ConfiguracaoRepositoryTest.war"

                      13:33:38,036 INFO  [org.jboss.as.jpa] (MSC service thread 1-6) JBAS011401: Read persistence.xml for horus-h2database

                      13:33:38,037 INFO  [org.jboss.as.jpa] (MSC service thread 1-6) JBAS011401: Read persistence.xml for horus-postgres

                      13:33:38,037 INFO  [org.jboss.as.jpa] (MSC service thread 1-6) JBAS011401: Read persistence.xml for horus-hsqldb

                      13:33:38,039 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-7) MSC00001: Failed to start service jboss.deployment.unit."ConfiguracaoRepositoryTest.war".DEPENDENCIES: org.jboss.msc.service.StartException in service jboss.deployment.unit."ConfiguracaoRepositoryTest.war".DEPENDENCIES: Failed to process phase DEPENDENCIES of deployment "ConfiguracaoRepositoryTest.war"

                           at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:119) [jboss-as-server-7.1.1.Final.jar:7.1.1.Final]

                           at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]

                           at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]

                           at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [rt.jar:1.7.0_17]

                           at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [rt.jar:1.7.0_17]

                           at java.lang.Thread.run(Thread.java:722) [rt.jar:1.7.0_17]

                      Caused by: java.lang.IllegalArgumentException: JBAS011470: Persistence unitName was not specified and there are 3 persistence unit definitions in application deployment "ConfiguracaoRepositoryTest.war".  Either change the application to have only one persistence unit definition or specify the unitName for each reference to a persistence unit.

                           at org.jboss.as.jpa.container.PersistenceUnitSearch.resolvePersistenceUnitSupplier(PersistenceUnitSearch.java:69)

                           at org.jboss.as.jpa.processor.JPAAnnotationParseProcessor.getPersistenceUnit(JPAAnnotationParseProcessor.java:284)

                           at org.jboss.as.jpa.processor.JPAAnnotationParseProcessor.getBindingSource(JPAAnnotationParseProcessor.java:220)

                           at org.jboss.as.jpa.processor.JPAAnnotationParseProcessor.processField(JPAAnnotationParseProcessor.java:151)

                           at org.jboss.as.jpa.processor.JPAAnnotationParseProcessor.processPersistenceAnnotations(JPAAnnotationParseProcessor.java:118)

                           at org.jboss.as.jpa.processor.JPAAnnotationParseProcessor.deploy(JPAAnnotationParseProcessor.java:90)

                           at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:113) [jboss-as-server-7.1.1.Final.jar:7.1.1.Final]

                           ... 5 more

                       

                      I suspect it's because of my qualifier used:

                       

                      public class DataRepositoryProducer {

                           @Produces

                           @DataRepository

                           @PersistenceContext

                           private EntityManager entityManager;

                      }

                       

                      Should I use a @Alternative? How can I solve and provide flexibility, with minimal configuration to achieve this?

                       

                      Thanks for Reply,

                      Cheers,

                      Marcos.

                      • 8. Re: Cannot Open Connection - arquillian-persistence-extension - H2Database
                        Bartosz Majsak Master

                        Oh, haven't looked that deeply. I think alternative might be one way... but on the other hand I would rather stick to one test-persistence.xml per mvn profile, as you will anyway use only one in the application, so why introducing additional complexity if not needed?

                        • 9. Re: Cannot Open Connection - arquillian-persistence-extension - H2Database
                          Bartosz Majsak Master

                          Have a look at this project to see how it can be organized using mvn profiles : https://github.com/bartoszmajsak/Beer-Advisor/blob/master/web/pom.xml#L184

                          1 of 1 people found this helpful
                          • 10. Re: Cannot Open Connection - arquillian-persistence-extension - H2Database
                            Bartosz Majsak Master

                            Moved from Arquillian Development to Arquillian, as it's the place for such threads.