您的位置:首页 > 数据库 > SQL

OpenJPA 输出 SQL 日志和使用连接池的方法

2010-06-07 16:17 435 查看

How do I see the SQL that OpenJPA is executing?

OpenJPA provides configurable channel-based logging, as described in the chapter on Logging. The simplest example of enabling verbose logging is by using the following property in your persistence.xml file:

<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
version="1.0">
<persistence-unit name="example-logging" transaction-type="RESOURCE_LOCAL">
<properties>
<property name="openjpa.Log" value="SQL=TRACE"/>
</properties>
</persistence-unit>
</persistence>
[/code]

How do I enable connection pooling in OpenJPA?

OpenJPA doesn't include any built-in connection pool, but you can use any third-party connection pool that is configurable via the JDBC DataSource API (which most are). The following persistence.xml example shows how to use OpenJPA with a Apache Derby database and the Apache DBCP connection pool:

<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
version="1.0">
<persistence-unit name="example-derby" transaction-type="RESOURCE_LOCAL">
<properties>
<property name="openjpa.ConnectionProperties"
value="DriverClassName=org.apache.derby.jdbc.ClientDriver,
Url=jdbc:derby://localhost:1527/database,
MaxActive=100,
MaxWait=10000,
TestOnBorrow=true,
Username=user,
Password=secret"/>
<property name="openjpa.ConnectionDriverName"
value="org.apache.commons.dbcp.BasicDataSource"/>
</properties>
</persistence-unit>
</persistence>
[/code]

See the documentation on Using a Third-Party DataSource for further details.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐