之前网上看了很多文章,但说的都不够详细,所以没有领会其中的含义。下面本人给出全部的文档。persistence.xml中,增加配置信息
<property name="openjpa.Log" value="log4j" />
1)jar包
commons-collections-3.2.jar
commons-lang-2.1.jar
commons-pool-1.3.jar
geronimo-jpa_3.0_spec-1.0.jar
geronimo-jta_1.1_spec-1.1.jar
openjpa-1.2.2.jar
serp-1.13.1.jar
mysql-connector-java-5.1.13-bin.jar
log4j-1.2.16.jar
2)persistence.xml
3)log4j.properties
log4j.rootLogger=INFO,appender1
# 控制台输出
log4j.category.openjpa.Tool=INFO
log4j.category.openjpa.Runtime=INFO
log4j.category.openjpa.Remote=WARN
log4j.category.openjpa.DataCache=WARN
log4j.category.openjpa.MetaData=WARN
log4j.category.openjpa.Enhance=WARN
log4j.category.openjpa.Query=WARN
log4j.category.openjpa.jdbc.SQL=WARN
log4j.category.openjpa.jdbc.JDBC=WARN
log4j.category.openjpa.jdbc.Schema=WARN
log4j.appender.appender1=org.apache.log4j.ConsoleAppender
log4j.appender.appender1.layout=org.apache.log4j.PatternLayout
log4j.appender.appender1.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss:SSS}[%p]: %m%n
# 立即输出
log4j.appender.appender1.immediateFlush=true
<property name="openjpa.Log" value="log4j" />
1)jar包
commons-collections-3.2.jar
commons-lang-2.1.jar
commons-pool-1.3.jar
geronimo-jpa_3.0_spec-1.0.jar
geronimo-jta_1.1_spec-1.1.jar
openjpa-1.2.2.jar
serp-1.13.1.jar
mysql-connector-java-5.1.13-bin.jar
log4j-1.2.16.jar
2)persistence.xml
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.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_1_0.xsd">
<persistence-unit name="MyJPA" transaction-type="RESOURCE_LOCAL">
<description>测试openjpa</description>
<provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
<non-jta-data-source>java:comp/env/jdbc/net</non-jta-data-source>
<class>entity.Animal</class>
<properties>
<property name="openjpa.Log" value="log4j" />
</properties>
</persistence-unit>
</persistence>
3)log4j.properties
log4j.rootLogger=INFO,appender1
# 控制台输出
log4j.category.openjpa.Tool=INFO
log4j.category.openjpa.Runtime=INFO
log4j.category.openjpa.Remote=WARN
log4j.category.openjpa.DataCache=WARN
log4j.category.openjpa.MetaData=WARN
log4j.category.openjpa.Enhance=WARN
log4j.category.openjpa.Query=WARN
log4j.category.openjpa.jdbc.SQL=WARN
log4j.category.openjpa.jdbc.JDBC=WARN
log4j.category.openjpa.jdbc.Schema=WARN
log4j.appender.appender1=org.apache.log4j.ConsoleAppender
log4j.appender.appender1.layout=org.apache.log4j.PatternLayout
log4j.appender.appender1.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss:SSS}[%p]: %m%n
# 立即输出
log4j.appender.appender1.immediateFlush=true