Friday, November 4, 2016

My errors #1 Unable to create connection, postgresql_Driver_9_4 is already registered

After all I'm recieving the errors:
 ERROR [org.hibernate.engine.jdbc.spi.SqlExceptionHelper] (ServerService Thread Pool -- 74) javax.resource.ResourceException: IJ000453: Unable to get managed connection for java:jboss/datasources/PostgresDS  

Caused because previous warnings:
 2016-11-04 23:56:27,637 WARN [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-8) WFLYJCA0003: Unable to instantiate driver class "org.postgresql.Driver": org.jboss.msc.service.DuplicateServiceException: Service jboss.jdbc-driver.catshelter-java_war_org_postgresql_Driver_9_4 is already registered  

 WARN [org.jboss.jca.core.connectionmanager.pool.strategy.OnePool] (ServerService Thread Pool -- 70) IJ000604: Throwable while attempting to get a new connection: null: javax.resource.ResourceException: IJ031084: Unable to create connection  
      at org.jboss.jca.adapters.jdbc.local.LocalManagedConnectionFactory.createLocalManagedConnection(LocalManagedConnectionFactory.java:345)  
      at org.jboss.jca.adapters.jdbc.local.LocalManagedConnectionFactory.getLocalManagedConnection(LocalManagedConnectionFactory.java:352)  
      at org.jboss.jca.adapters.jdbc.local.LocalManagedConnectionFactory.createManagedConnection(LocalManagedConnectionFactory.java:287)  
      at org.jboss.jca.core.connectionmanager.pool.mcp.SemaphoreConcurrentLinkedDequeManagedConnectionPool.createConnectionEventListener(SemaphoreConcurrentLinkedDequeManagedConnectionPool.java:1320)  
      at org.jboss.jca.core.connectionmanager.pool.mcp.SemaphoreConcurrentLinkedDequeManagedConnectionPool.getConnection(SemaphoreConcurrentLinkedDequeManagedConnectionPool.java:496)  
      at org.jboss.jca.core.connectionmanager.pool.AbstractPool.getSimpleConnection(AbstractPool.java:617)  
      at org.jboss.jca.core.connectionmanager.pool.AbstractPool.getConnection(AbstractPool.java:589)  
      at org.jboss.jca.core.connectionmanager.AbstractConnectionManager.getManagedConnection(AbstractConnectionManager.java:590)  
      at org.jboss.jca.core.connectionmanager.tx.TxConnectionManagerImpl.getManagedConnection(TxConnectionManagerImpl.java:429)  
      at org.jboss.jca.core.connectionmanager.AbstractConnectionManager.allocateConnection(AbstractConnectionManager.java:747)  
      at org.jboss.jca.adapters.jdbc.WrapperDataSource.getConnection(WrapperDataSource.java:138)  
      at org.jboss.as.connector.subsystems.datasources.WildFlyDataSource.getConnection(WildFlyDataSource.java:66)  
      at org.hibernate.engine.jdbc.connections.internal.DatasourceConnectionProviderImpl.getConnection(DatasourceConnectionProviderImpl.java:122)  
      at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator$ConnectionProviderJdbcConnectionAccess.obtainConnection(JdbcEnvironmentInitiator.java:180)  
      at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:68)  
      at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:35)  
      at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.initiateService(StandardServiceRegistryImpl.java:88)  
      at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:254)  
      at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:228)  
      at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:207)  
      at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:51)  
      at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:94)  
      at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:237)  
      at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:207)  
      at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.handleTypes(MetadataBuildingProcess.java:352)  
      at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:111)  
      at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.metadata(EntityManagerFactoryBuilderImpl.java:847)  
      at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:874)  
      at org.jboss.as.jpa.hibernate5.TwoPhaseBootstrapImpl.build(TwoPhaseBootstrapImpl.java:44)  
      at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:161)  
      at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:121)  
      at org.wildfly.security.manager.WildFlySecurityManager.doChecked(WildFlySecurityManager.java:667)  
      at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1.run(PersistenceUnitServiceImpl.java:193)  
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)  
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)  
      at java.lang.Thread.run(Thread.java:745)  
      at org.jboss.threads.JBossThread.run(JBossThread.java:320)  
 Caused by: javax.resource.ResourceException: IJ031089: Failed to load datasource: org.postgresql.Driver  
      at org.jboss.jca.adapters.jdbc.local.LocalManagedConnectionFactory.getDataSource(LocalManagedConnectionFactory.java:652)  
      at org.jboss.jca.adapters.jdbc.local.LocalManagedConnectionFactory.createLocalManagedConnection(LocalManagedConnectionFactory.java:313)  
      ... 36 more  
 Caused by: java.lang.ClassCastException: org.postgresql.Driver cannot be cast to javax.sql.DataSource  
      at org.jboss.jca.adapters.jdbc.local.LocalManagedConnectionFactory.getDataSource(LocalManagedConnectionFactory.java:635)  
      ... 37 more  

First of all: wrong hibernate settings in persistance.xml. I went to google and took ones for Postgres:
 <?xml version="1.0" encoding="UTF-8"?>  
   
 <persistence version="2.1"  
        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_1.xsd">  
   <persistence-unit name="postgres">  
     <!-- If you are running in a production environment, add a managed  
       data source, this example data source is just for development and testing! -->  
     <!-- The datasource is deployed as WEB-INF/greeter-quickstart-ds.xml,  
       you can find it in the source at src/main/webapp/WEB-INF/greeter-quickstart-ds.xml -->  
     <jta-data-source>java:jboss/datasources/PostgresDS</jta-data-source>  
     <!--Next is for version 9.4 and higher -->
     <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>  
     <properties>  
      <!--  <property name="hibernate.archive.autodetection" value="class" /> -->  
       <property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQL94Dialect" />  
       <!--  this I comment because I already have my connection registered as a module
       <property name="hibernate.connection.driver_class" value="org.postgresql.Driver" />  
       <property name="hibernate.connection.url" value="jdbc:postgresql://localhost:5433/cats" />  
       <property name="hibernate.connection.username" value="postgres" />  
       <property name="hibernate.connection.password" value="mei" />  
       Next I setup value of show_sql for false and hb2ddl.auto for "create-drop"-->  
       <property name="hibernate.show_sql" value="false"/>  
       <property name="hibernate.flushMode" value="FLUSH_AUTO" />  
       <property name="hibernate.hbm2ddl.auto" value="create-drop" />  
     </properties>  
   </persistence-unit>  
 </persistence>  
   

Then I need to add some new dependencies to my pom.xml:
     <dependency>  
       <groupId>org.hibernate</groupId>  
       <artifactId>hibernate-entitymanager</artifactId>  
       <version>5.2.4.Final</version>  
     </dependency>   
   
     <dependency>  
       <groupId>org.postgresql</groupId>  
       <artifactId>postgresql</artifactId>  
       <version>9.4.1211</version>  
     </dependency>  

Then I've got a BUILD SUCCESS wiht my project deployment.

No comments:

Post a Comment