How can I configure JPA for a postgres database schema?

只愿长相守 提交于 2021-01-29 06:34:18

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!