使用JNDI在glassfish上查找JDBC资源

时间:2014-10-28 06:34:14

标签: jpa jdbc glassfish eclipselink persistence.xml

一般来说,如何将库中的persistence.xml配置为使用与EclipseLink和JPA的JDBC连接池?

当企业应用程序的Web模块使用库时,库的配置文件被组织为通过JNDI查找引用Glassfish上的JDBC资源?

具体来说,这是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="EJBRemoteInterfacePU" transaction-type="RESOURCE_LOCAL">
    <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
    <class>dur.jpa.Client</class>
    <properties>
      <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/legacy?zeroDateTimeBehavior=convertToNull"/>
      <property name="javax.persistence.jdbc.password" value="password"/>
      <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
      <property name="javax.persistence.jdbc.user" value="jdbc"/>
    </properties>
  </persistence-unit>
</persistence>

已更改为使用下面的jdbc/legacy_resource

asadmin> 
asadmin> list-jdbc-resources
jdbc/sample
jdbc/__TimerPool
jdbc/__default
jdbc/local
jdbc/legacy_resource
Command list-jdbc-resources executed successfully.
asadmin> 
asadmin> list-jdbc-connection-pools
CLI031: Warning: Option "target" is obsolete and will be ignored.
CLI031: Warning: Option "target" is obsolete and will be ignored.
__TimerPool
DerbyPool
SamplePool
connectionPool
legacy_on_glassfish
Command list-jdbc-connection-pools executed successfully.
asadmin> 

另见:

http://wiki.eclipse.org/EclipseLink/Examples/JPA/GlassFishV2_Web_Tutorial

http://javahowto.blogspot.ca/2011/02/sample-glassfish-resourcesxml.html

0 个答案:

没有答案