问题
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.
回答1:
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>
来源:https://stackoverflow.com/questions/53176091/how-can-i-configure-jpa-for-a-postgres-database-schema