Netbeans generate config files for JTA Transaction automatically

If you are using Netbeans, you are lucky. When you create the persistence.xml, netbeans will help you build the config-xml of JTA automatically.
I use Netbeans 6.9, EJB 3.1, JPA 2.0, JSF 2.0.
But, if you are using eclipse, you should modify the content of persistence.xml, maybe it should like this:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0"
	xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
	<persistence-unit name="FromWebPU" transaction-type="JTA">
		<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
		<jta-data-source>FromWebJndi</jta-data-source>
		<class>HelloMessage</class>
		<properties>
			<property name="eclipselink.ddl-generation" value="drop-and-create-tables" />
		</properties>
	</persistence-unit>
</persistence>

That's not enough, you should also add a file named "sun-resources.xml" under the folder of "web-inf". Its content like this:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE resources PUBLIC "-//Sun Microsystems, Inc.//DTD Application Server 9.0 Resource Definitions //EN" "http://www.sun.com/software/appserver/dtds/sun-resources_1_3.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="com.mysql.jdbc.jdbc2.optional.MysqlDataSource" 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="mysql_fromWeb_rootPool" 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="3306"/>
        <property name="databaseName" value="fromWeb"/>
        <property name="User" value="root"/>
        <property name="Password" value="root"/>
        <property name="URL" value="jdbc:mysql://localhost:3306/fromWeb"/>
        <property name="driverClass" value="com.mysql.jdbc.Driver"/>
    </jdbc-connection-pool>
    <jdbc-resource enabled="true" jndi-name="FromWebJndi" object-type="user" pool-name="mysql_fromWeb_rootPool"/>
</resources>

You know, I get the file "sun-resources.xml" from netbeans....
BTW:My workmate use eclipse, he didn't know what's wrong with his program for several days, finally he realized that the transaction-type of the persistence should be "JTA" after he read my program which was coded in netbeans.Then I gave him the two config files.

你可能感兴趣的:(eclipse,jpa,ejb,Netbeans,Glassfish)