【问题标题】:How can I configure JPA for a postgres database schema?如何为 postgres 数据库模式配置 JPA?
【发布时间】:2019-04-10 02:14:32
【问题描述】:

我有一个现有的 postgres 数据库,其中包含数据库“testdb”和数据库架构 testdbschema”。

如果我使用 RESOURCE_LOCAL 的默认 persistence.xml 配置,则以下属性有效:

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

我想将我的 web.xml 中的数据库连接配置为数据源。一切都运行良好,除了数据库模式的配置。

这是我的 web.xml 配置:

<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>

您现在如何在此处配置我的数据库架构名称?

通过 testdb?currentSchema=testdbschema 的配置对我不起作用,我得到一个找不到数据库的失败。

【问题讨论】:

标签: java postgresql jpa datasource web.xml


【解决方案1】:

在 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>

【讨论】:

    猜你喜欢
    • 2012-05-19
    • 2014-03-25
    • 2020-05-30
    • 1970-01-01
    • 2015-06-25
    • 1970-01-01
    • 1970-01-01
    • 2017-10-14
    • 1970-01-01
    相关资源
    最近更新 更多