我已经阅读了一些答案,如追加?searchpath = myschema或?currentSchema = myschema,但它仍然不起作用在我的情况。我使用NetBeans,并且可以执行命令到与预期模式的连接,它运行良好,但在运行时,Glassfish只连接到公共模式,忽略?currentSchema = myschema。我的PostgreSQL的版本是9.6和JDBC驱动程序的版本是最新的42.0.0在glassfish jdbc连接池中指定模式?
这是我与GlassFish resource.xml:
<resources>
<jdbc-connection-pool allow-non-component-callers="false" associate-with-thread="false" connection-creation-retry-attempts="0" connection-creation-retry-interval-in-seconds="10" connection-leak-reclaim="false" connection-leak-timeout-in-seconds="0" connection-validation-method="auto-commit" datasource-classname="org.postgresql.ds.PGSimpleDataSource" fail-all-connections="false" idle-timeout-in-seconds="300" is-connection-validation-required="false" is-isolation-level-guaranteed="true" lazy-connection-association="false" lazy-connection-enlistment="false" match-connections="false" max-connection-usage-count="0" max-pool-size="32" max-wait-time-in-millis="60000" name="post-gre-sql_aegwyncreds_dbexerphi_dbaPool" non-transactional-connections="false" pool-resize-quantity="2" res-type="javax.sql.DataSource" statement-timeout-in-seconds="-1" steady-pool-size="8" validate-atmost-once-period-in-seconds="0" wrap-jdbc-objects="false">
<property name="serverName" value="localhost"/>
<property name="portNumber" value="5432"/>
<property name="databaseName" value="mydb"/>
<property name="User" value="user"/>
<property name="Password" value="pass"/>
<property name="URL" value="jdbc:postgresql://localhost:5432/mydb?currentSchema=myschema"/>
<property name="driverClass" value="org.postgresql.Driver"/>
</jdbc-connection-pool>
<jdbc-resource enabled="true" jndi-name="java:app/myjndisource" object-type="user" pool-name="post-gre-sql_mydb_user_dbaPool"/>
</resources>
这是我的执着单位:
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
<persistence-unit name="myPU" transaction-type="JTA">
<jta-data-source>java:app/myjndisource</jta-data-source>
<class>myclass</class>
. . . . . . . . . .
<exclude-unlisted-classes>true</exclude-unlisted-classes>
<properties>
</properties>
</persistence-unit>
</persistence>
架构不是连接字符串的一部分。尝试将它追加到关系名称上? –
@VaoTsun [PostgreSQL JDBC文档](https://jdbc.postgresql.org/documentation/94/connect。html#connection-parameters)会有所不同:_“'currentSchema = String'指定要在搜索路径中设置的模式,该模式将用于解析通过此连接的语句中使用的非限定对象名称。”_ –
@ Vao Tsun,将其添加到关系名称?你的意思是实体类中的实体还是表注释属性?但我想要一个类在多个模式中使用。 – Mideel