3 Replies Latest reply on Oct 28, 2014 3:30 PM by Oliver Hernandez

    Problems with H2 and Hibernate

    Troy Bronzan Newbie

      I'm trying to get a H2 in-memory database set up and working but I can't seem to connect to it.  I'm using the default datasource in standalone.xml but when my application is deployed and the persistence.xml is processed, I keep getting an error saying that the username or password is wrong.  I find this very odd because I'm referencing the datasource via JNDI, so it should be using the credentials in the datasource definition in standalone.xml.  I'm not even trying  reference the persistence unit at this point, these errors happen on start up.  Any help would be greatly appreciated.

       

      standalone.xml

      <datasource jndi-name="java:jboss/datasources/ExampleDS" pool-name="ExampleDS" enabled="true" use-java-context="true">
           <connection-url>jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;</connection-url>
           <driver>h2</driver>
           <security>
                <user-name>sa</user-name>
                <password>sa</password>
           </security>
      </datasource>
      

       

      persistence.xml

      <persistence-unit name="inmemory" transaction-type="JTA">
           <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
           <jta-data-source>java:jboss/datasources/ExampleDS</jta-data-source>
           <class>com.foo.SomeEntity</class>
           <exclude-unlisted-classes>true</exclude-unlisted-classes>
           <properties>
                <property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect" />
                <property name="hibernate.show_sql" value="false" />
           </properties>
      </persistence-unit>
      

       

      stack trace

      09:57:11,471 ERROR [org.hibernate.tool.hbm2ddl.SchemaUpdate] (ServerService Thread Pool -- 59) HHH000319: Could not get database metadata: java.sql.SQLException: javax.resource.ResourceException: IJ000453: Unable to get managed connection for java:jboss/datasources/ExampleDS
        at org.jboss.jca.adapters.jdbc.WrapperDataSource.getConnection(WrapperDataSource.java:150)
        at org.hibernate.engine.jdbc.connections.internal.DatasourceConnectionProviderImpl.getConnection(DatasourceConnectionProviderImpl.java:139) [hibernate-core-4.3.1.Final.jar:4.3.1.Final]
        at org.hibernate.tool.hbm2ddl.SuppliedConnectionProviderConnectionHelper.prepare(SuppliedConnectionProviderConnectionHelper.java:51) [hibernate-core-4.3.1.Final.jar:4.3.1.Final]
        at org.hibernate.tool.hbm2ddl.SchemaUpdate.execute(SchemaUpdate.java:194) [hibernate-core-4.3.1.Final.jar:4.3.1.Final]
        at org.hibernate.tool.hbm2ddl.SchemaUpdate.execute(SchemaUpdate.java:178) [hibernate-core-4.3.1.Final.jar:4.3.1.Final]
        at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:521) [hibernate-core-4.3.1.Final.jar:4.3.1.Final]
        at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1857) [hibernate-core-4.3.1.Final.jar:4.3.1.Final]
        at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:850) [hibernate-entitymanager-4.3.1.Final.jar:4.3.1.Final]
        at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:843) [hibernate-entitymanager-4.3.1.Final.jar:4.3.1.Final]
        at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.withTccl(ClassLoaderServiceImpl.java:399) [hibernate-core-4.3.1.Final.jar:4.3.1.Final]
        at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:842) [hibernate-entitymanager-4.3.1.Final.jar:4.3.1.Final]
        at org.jboss.as.jpa.hibernate4.TwoPhaseBootstrapImpl.build(TwoPhaseBootstrapImpl.java:44) [jipijapa-hibernate4-3-1.0.1.Final.jar:]
        at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:154) [wildfly-jpa-8.0.0.Final.jar:8.0.0.Final]
        at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:117) [wildfly-jpa-8.0.0.Final.jar:8.0.0.Final]
        at java.security.AccessController.doPrivileged(Native Method) [rt.jar:1.7.0_45]
        at org.wildfly.security.manager.WildFlySecurityManager.doChecked(WildFlySecurityManager.java:474) [wildfly-security-manager-1.0.0.Final.jar:1.0.0.Final]
        at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1.run(PersistenceUnitServiceImpl.java:182) [wildfly-jpa-8.0.0.Final.jar:8.0.0.Final]
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [rt.jar:1.7.0_45]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [rt.jar:1.7.0_45]
        at java.lang.Thread.run(Thread.java:744) [rt.jar:1.7.0_45]
        at org.jboss.threads.JBossThread.run(JBossThread.java:122) [jboss-threads-2.1.1.Final.jar:2.1.1.Final]
      Caused by: javax.resource.ResourceException: IJ000453: Unable to get managed connection for java:jboss/datasources/ExampleDS
        at org.jboss.jca.core.connectionmanager.AbstractConnectionManager.getManagedConnection(AbstractConnectionManager.java:440) [ironjacamar-core-impl-1.1.3.Final.jar:1.1.3.Final]
        at org.jboss.jca.core.connectionmanager.tx.TxConnectionManagerImpl.getManagedConnection(TxConnectionManagerImpl.java:422) [ironjacamar-core-impl-1.1.3.Final.jar:1.1.3.Final]
        at org.jboss.jca.core.connectionmanager.AbstractConnectionManager.allocateConnection(AbstractConnectionManager.java:513) [ironjacamar-core-impl-1.1.3.Final.jar:1.1.3.Final]
        at org.jboss.jca.adapters.jdbc.WrapperDataSource.getConnection(WrapperDataSource.java:142)
        ... 20 more
      Caused by: javax.resource.ResourceException: IJ000658: Unexpected throwable while trying to create a connection: null
        at org.jboss.jca.core.connectionmanager.pool.mcp.SemaphoreArrayListManagedConnectionPool.getConnection(SemaphoreArrayListManagedConnectionPool.java:490) [ironjacamar-core-impl-1.1.3.Final.jar:1.1.3.Final]
        at org.jboss.jca.core.connectionmanager.pool.AbstractPool.getSimpleConnection(AbstractPool.java:452) [ironjacamar-core-impl-1.1.3.Final.jar:1.1.3.Final]
        at org.jboss.jca.core.connectionmanager.pool.AbstractPool.getConnection(AbstractPool.java:420) [ironjacamar-core-impl-1.1.3.Final.jar:1.1.3.Final]
        at org.jboss.jca.core.connectionmanager.AbstractConnectionManager.getManagedConnection(AbstractConnectionManager.java:379) [ironjacamar-core-impl-1.1.3.Final.jar:1.1.3.Final]
        ... 23 more
      Caused by: javax.resource.ResourceException: Could not create connection
        at org.jboss.jca.adapters.jdbc.local.LocalManagedConnectionFactory.createLocalManagedConnection(LocalManagedConnectionFactory.java:304)
        at org.jboss.jca.adapters.jdbc.local.LocalManagedConnectionFactory.getLocalManagedConnection(LocalManagedConnectionFactory.java:311)
        at org.jboss.jca.adapters.jdbc.local.LocalManagedConnectionFactory.createManagedConnection(LocalManagedConnectionFactory.java:246)
        at org.jboss.jca.core.connectionmanager.pool.mcp.SemaphoreArrayListManagedConnectionPool.createConnectionEventListener(SemaphoreArrayListManagedConnectionPool.java:1144) [ironjacamar-core-impl-1.1.3.Final.jar:1.1.3.Final]
        at org.jboss.jca.core.connectionmanager.pool.mcp.SemaphoreArrayListManagedConnectionPool.getConnection(SemaphoreArrayListManagedConnectionPool.java:446) [ironjacamar-core-impl-1.1.3.Final.jar:1.1.3.Final]
        ... 26 more
      Caused by: org.h2.jdbc.JdbcSQLException: Wrong user name or password [28000-173]
        at org.h2.message.DbException.getJdbcSQLException(DbException.java:331)
        at org.h2.message.DbException.get(DbException.java:171)
        at org.h2.message.DbException.get(DbException.java:148)
        at org.h2.message.DbException.get(DbException.java:137)
        at org.h2.engine.Engine.validateUserAndPassword(Engine.java:302)
        at org.h2.engine.Engine.createSessionAndValidate(Engine.java:147)
        at org.h2.engine.Engine.createSession(Engine.java:122)
        at org.h2.engine.Engine.createSession(Engine.java:28)
        at org.h2.engine.SessionRemote.connectEmbeddedOrServer(SessionRemote.java:313)
        at org.h2.jdbc.JdbcConnection.<init>(JdbcConnection.java:105)
        at org.h2.jdbc.JdbcConnection.<init>(JdbcConnection.java:90)
        at org.h2.Driver.connect(Driver.java:73)
        at org.jboss.jca.adapters.jdbc.local.LocalManagedConnectionFactory.createLocalManagedConnection(LocalManagedConnectionFactory.java:279)
        ... 30 more