Uploaded image for project: 'WildFly'
  1. WildFly
  2. WFLY-6800

Database ignored in Postgres JDBC URL

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: Major Major
    • None
    • 10.0.0.Final
    • JPA / Hibernate
    • None
    • java 8
      windows 7
      postgresql 9.4

    • Hide

      Install postgres 9.4

      Create a maven project with the archetype wildfly-javaee7-webapp-ear-archetype

      Create a JDBC driver postgres 9.4 in standlone-full.xml

      Create a postgres datasource in standlone-full.xml with any database name (don't create the database)

      Reference this datasource from the persistence unit

      Deploy and test the project. Lauch pgadmin III and explore dataabses. Schema and data are in "postgres" database, the name provided in the datasource url is ignored.

      Remark : as I don't know if this is a posgres JDBC driver bug, I also declared a bug in postgres : #14224

      Show
      Install postgres 9.4 Create a maven project with the archetype wildfly-javaee7-webapp-ear-archetype Create a JDBC driver postgres 9.4 in standlone-full.xml Create a postgres datasource in standlone-full.xml with any database name (don't create the database) Reference this datasource from the persistence unit Deploy and test the project. Lauch pgadmin III and explore dataabses. Schema and data are in "postgres" database, the name provided in the datasource url is ignored. Remark : as I don't know if this is a posgres JDBC driver bug, I also declared a bug in postgres : #14224

      I created a data source like this

                      <datasource jndi-name="java:jboss/datasources/crawlRuntimeDS" pool-name="crawlRuntimePool" enabled="true" use-java-context="true">
                          <connection-url>jdbc:postgresql://localhost:5432/runtimedb</connection-url>
                          <driver>postgresDD</driver>
                          <security>
                              <user-name>postgres</user-name>
                              <password>postgres</password>
                          </security>
                      </datasource>
      
      I reference it in a persistent unit:
      
      	<persistence-unit name="crawl-runtime-pu">
      		<jta-data-source>java:jboss/datasources/crawlRuntimeDS</jta-data-source>
      
      		<class>org.mvera.webscrap.model.crawl.runtime.CrawlEntity</class>
      		<class>org.mvera.webscrap.model.crawl.runtime.PageCrawlStatusEntity</class>
      
      		<exclude-unlisted-classes>true</exclude-unlisted-classes>
      
      		<properties>
      			<property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect" />
      			<property name="hibernate.show_sql" value="true" />
      			<property name="hibernate.format_sql" value="true" />
      
      			<property name="javax.persistence.schema-generation.database.action"
      				value="none" />
      			<property name="javax.persistence.schema-generation.scripts.action"
      				value="drop-and-create" />
      			<property name="javax.persistence.schema-generation.scripts.create-target"
      				value="D:/mvera/crawl-runtime-pu-create.sql" />
      			<property name="javax.persistence.schema-generation.scripts.drop-target"
      				value="D:/mvera/crawl-runtime-pu-drop.sql" />
      		</properties>
      
      	</persistence-unit>
      

      I thought for a moment that all was working right. My data was persisted and I could read it from within an EJB using this datasource. But then I discovered that my data was not persisted at all in the database "crawlRuntimeDS" specified on the jdbc URL of the datasource but in the database "postgres" (a default database created during install of postgres).

      This is a real problem as my application uses serveral databases (several persistence units). The workaround today is to put all entities in the same "postgres" database.

      In the datasource, I can put any name as the database name, it is ignored, even if the database doesn't exist.

              smarlow1@redhat.com Scott Marlow
              mvera31 mickael vera (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Created:
                Updated:
                Resolved: