0

I have an existing postgres database with the database "testdb" and the database schema testdbschema".

If I use the default persistence.xml configuration of RESOURCE_LOCAL the following property is working:

<property name="javax.persistence.jdbc.url" value="jdbc:postgresql://server:port/testdb?currentSchema=testdbschema" /> 

I want to configure my database connection within my web.xml as a data-source. Everything is working well, except the configuration of the database schema.

Here is my web.xml configuration:

<data-source>
    <name>java:global/myapp</name>
    <class-name>org.postgresql.ds.PGSimpleDataSource</class-name>
    <server-name>127.0.0.1</server-name>
    <port-number>5432</port-number>
    <database-name>testdb</database-name> 
    <user>postgres</user>
    <password>postgres</password>
</data-source>

Do you now how can I configure my db schema name here?

The configuration via testdb?currentSchema=testdbschema did not work for me and I get a database not found failure.

  • did you try ${yourSchema} – greengreyblue Nov 06 '18 at 16:39
  • Possible duplicate of [is there a standard way to define a JDBC Datasource for Java EE containers?](https://stackoverflow.com/questions/2279913/is-there-a-standard-way-to-define-a-jdbc-datasource-for-java-ee-containers) –  Nov 06 '18 at 16:41
  • I want to configure it within the web.xml and not within the hibernate persistence.xml file. This JDBC datasource thread did not describe the handling of database schema. – Andreas B. Nov 07 '18 at 08:13

1 Answers1

0

The solution was found within the PGSimpleDataSource:

<data-source>
    <name>java:global/myapp</name>
    <class-name>org.postgresql.ds.PGSimpleDataSource</class-name>
    <server-name>127.0.0.1</server-name>
    <port-number>5432</port-number>
    <database-name>testdb</database-name>
    <user>postgres</user>
    <password>postgres</password>

    <property>
        <name>currentSchema</name>
        <value>testdbschema</value>
    </property>