Glassfish:资源无效

时间:2016-11-08 11:59:10

标签: java jdbc netbeans glassfish ejb

我有EJB模块,想在Glassfish上部署。我配置了JDBC池和资源并ping成功。但是在部署我的模块时遇到此错误。 我的Java DB只调用“Bank”,但Glassfih写的是“Bank_pm”。

的persistence.xml

<formly-transclude></formly-transclude>
<div class="messages" ng-messages="fc.$error" ng-if="fc.$touched">
  <div class="alert alert-danger"
     ng-message="{{::name}}"
     ng-repeat="(name, message) in ::options.validation.messages"
     translate>
    {{message(fc.$viewValue, fc.$modelValue, this)}}
  </div>
</div>

的glassfish-resources.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="ClientManager" transaction-type="JTA">
    <jta-data-source>jdbc:derby://localhost:1527/Bank</jta-data-source>
    <exclude-unlisted-classes>false</exclude-unlisted-classes>
    <properties>
      <property name="javax.persistence.schema-generation.database.action" value="create"/>
    </properties>
  </persistence-unit>
</persistence>
enter code here

Glassfish日志

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE resources PUBLIC "-//GlassFish.org//DTD GlassFish Application Server 3.1 Resource Definitions//EN" "http://glassfish.org/dtds/glassfish-resources_1_5.dtd">
<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.apache.derby.jdbc.ClientDataSource" 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="connectionPool" 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="URL" value="jdbc:derby://localhost:1527/Bank"/>
    <property name="serverName" value="localhost"/>
    <property name="PortNumber" value="1527"/>
    <property name="DatabaseName" value="Bank"/>
    <property name="User" value="Bank"/>
    <property name="Password" value="1234"/>
  </jdbc-connection-pool>
</resources>

1 个答案:

答案 0 :(得分:0)

  

问题是您在&lt;中提供了连接URL。 jta-data-source&gt;这是不正确的。

     

这里我们应该指定JNDI名称而不是连接字符串,设置连接URL的正确方法是在&lt;属性&gt;标签

在下面的解决方案中,我在name标记下的glassfish-resources.xml添加了resource属性。

然后我在标签

下的persistence.xml中引用了创建的资源名称

更改您的glassfish-resources.xml,如下所示

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE resources PUBLIC "-//GlassFish.org//DTD GlassFish Application Server 3.1 Resource Definitions//EN" "http://glassfish.org/dtds/glassfish-resources_1_5.dtd">
<resources>
  <jdbc-connection-pool name="jdbc/Bank" 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.apache.derby.jdbc.ClientDataSource" 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="connectionPool" 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="URL" value="jdbc:derby://localhost:1527/Bank"/>
    <property name="serverName" value="localhost"/>
    <property name="PortNumber" value="1527"/>
    <property name="DatabaseName" value="Bank"/>
    <property name="User" value="Bank"/>
    <property name="Password" value="1234"/>
  </jdbc-connection-pool>
</resources>

然后更改你的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="ClientManager" transaction-type="JTA">
    <jta-data-source>jdbc/Bank</jta-data-source>
    <exclude-unlisted-classes>false</exclude-unlisted-classes>
    <properties>
      <property name="javax.persistence.schema-generation.database.action" value="create"/>
    </properties>
  </persistence-unit>
</persistence>