如何为Postgres数据库架构配置JPA? [英] How can I configure JPA for a postgres database schema?

查看:87
本文介绍了如何为Postgres数据库架构配置JPA?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个现有的postgres数据库,其中包含数据库"testdb"和数据库模式"testdbschema".

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

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

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

我想将我的web.xml中的数据库连接配置为数据源.除了数据库模式的配置之外,其他所有东西都运行良好.

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.

这是我的web.xml配置:

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>

您现在如何在此处配置数据库模式名称?

通过testdb?currentSchema = testdbschema进行的配置对我不起作用,并且我发现数据库未找到失败.

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

推荐答案

在PGSimpleDataSource中找到了解决方案:

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>

这篇关于如何为Postgres数据库架构配置JPA?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆