我使用netbeans(8.0.2)中的持久性单元向导创建了数据源。但是当在glassfish上运行项目时,它无法找到我的数据源。
异常
异常说明:无法获取数据源[blogdb]。内部 例外:javax.naming.NamingException:'blogdb'中的查找失败 SerialContext [myEnv = {java.naming.factory.initial的= com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.state = com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs = com.sun.enterprise.naming} [Root 异常是javax.naming.NameNotFoundException:找不到blogdb]
的persistence.xml
<?xml version="1.0" encoding="UTF-8"?>
<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="BloggerPU" transaction-type="JTA">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<jta-data-source>blogdb</jta-data-source>
<properties>
<property name="javax.persistence.schema-generation.database.action" value="create"/>
</properties>
</persistence-unit>
</persistence>
的glassfish-resources.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_2TX33_r0457020Pool" 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"server.domain.com"/>
<property name="portNumber" value="51415"/>
<property name="databaseName" value="2TX33"/>
<property name="User" value="user"/>
<property name="Password" value="pass"/>
<property name="URL" value="jdbc:postgresql://server.domain.com:51415/2TX33"/>
<property name="driverClass" value="org.postgresql.Driver"/>
</jdbc-connection-pool>
<jdbc-resource enabled="true" jndi-name="blogdb" object-type="user" pool-name="post-gre-sql_2TX33_r0457020Pool"/>
我正在使用EclipseLink JPA 2.1
答案 0 :(得分:0)
我的问题是我在glassfish服务器上部署了另一个使用相同jta-datasource的应用程序。