我已經閱讀了一些答案,如追加?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