如何创建 jta-data-source 文件?

how to create a jta-data-source file?

我正在使用 Glassfish 4.1。 这是我希望我的 persistence.xml 文件的样子:

<persistence-unit name="PU" transaction-type="JTA">        
    <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
    <jta-data-source>PostgreDS</jta-data-source>
    <exclude-unlisted-classes>false</exclude-unlisted-classes>
</persistence-unit>

我不知道如何或在哪里创建 'PostgreDS' 文件。

您需要在 glassfish-resources.xml 文件中描述您的数据源,并将此文件放在 webapp/WEB-INF 文件夹下。

看看这个article

只是为了 mexes_s 回答的完整性。这是我最终用于配置 PostgreSQL 连接的文件。

<?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.postgresql.ds.PGPoolingDataSource" 
        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="java:app/jdbc/PostgreSQLPool" 
        non-transactional-connections="false" 
        pool-resize-quantity="2" 
        res-type="javax.sql.ConnectionPoolDataSource" 
        statement-timeout-in-seconds="-1" 
        steady-pool-size="8" 
        validate-atmost-once-period-in-seconds="0" 
        wrap-jdbc-objects="false">    
    <property name="user" value="postgres"/>
    <property name="portNumber" value="5432"/>
    <property name="password" value="postgres"/>
    <property name="serverName" value="localhost"/>
    <property name="databaseName" value="PostgreSQLDB"/>
    <property name="URL" value="jdbc:postgresql://localhost:5432/PostgreSQLDB"/>
    <property name="driverClass" value="org.postgresql.ds.PGPoolingDataSource"/>
    <property name="connectionAttributes" value=";create=true"/>
</jdbc-connection-pool>
<jdbc-resource 
        enabled="true" 
        jndi-name="java:app/jdbc/PostgreSQLDS" 
        object-type="user" 
        pool-name="java:app/jdbc/PostgreSQLPool"/>
</resources>