0

I want to configure a data source in Payara 5 using PostgresQL as the database. This is my code from web.xml:

<data-source>
    <name>java:global/my_ds</name>
    <class-name>org.postgresql.ds.PGSimpleDataSource</class-name>
    <server-name>postgres.host.test</server-name>
    <port-number>0</port-number>
    <database-name>mydb</database-name>
    <user>user</user>
    <password>pwd</password>
</data-source>

This works fine. However I need to set the current schema on the data source. There is a method on PGSimpleDataSource to do so, so I could do that programmatically. However I'd like to configure the current schema along with the other options. To that end, I tried:

  1. Adding another child tag called <current-schema>my-schema</current-schema> to the <data-source> tag. My IDE complained that this additional tag is not allowed.
  2. Adding a property with names current-schema and currentSchema to the <data-source> tag. That was allowed, but had no effect.

So, now I'm looking for the way that actually works.

Matthias Rothe
  • 101
  • 1
  • 6
  • 1
    Sorry, just to clarify: did you add a property with names `my-schema` or `currentSchemamy-schema`? Also, would it maybe possible for you to specify the schema in the URL? https://stackoverflow.com/questions/4168689/is-it-possible-to-specify-the-schema-when-connecting-to-postgres-with-jdbc – Christoph John Feb 05 '20 at 17:10
  • No worries, I used ```currentSchemamy-schema``` and ```current-schemamy-schema```. As there is no URL in this scenario I can't specify the current schema in it. Trying to specify it in the database-name also didn't work. – Matthias Rothe Feb 05 '20 at 17:24

1 Answers1

0

As How can I configure JPA for a postgres database schema? suggests the solution is indeed to configure a property like so:

<data-source>
    <name>java:global/my_ds</name>
    <class-name>org.postgresql.ds.PGSimpleDataSource</class-name>
    <server-name>postgres.host.test</server-name>
    <port-number>0</port-number>
    <database-name>mydb</database-name>
    <user>user</user>
    <password>pwd</password>

    <!-- This is the correct property -->
    <property>
        <name>currentSchema</name>
        <value>my-schema</value>
    </property>

</data-source>
Matthias Rothe
  • 101
  • 1
  • 6
  • So how is this different from what you tried as per the comments above? ;) Did you forget to specify `` tags before or what was the problem? – Christoph John Feb 17 '20 at 12:54
  • Honestly, I don't know what the problem was. When I first tried it, it didn't work. When I tried it again, it worked. – Matthias Rothe Mar 02 '20 at 10:28