如何配置OpenJPA的SQL日志?(How do I configure OpenJPA SQL

2019-07-29 13:04发布

什么是OpenJPA配置来查看在数据库中执行SQL查询? 我想查看与日志或控制台,而不是观看JPQL查询执行的所有参数查询

Answer 1:

<property name="openjpa.Log" value="SQL=Trace" />

启用所有SQL语句,减去参数值的记录。

<property name="openjpa.ConnectionFactoryProperties" value="PrintParameters=true" />

启用的SQL参数记录。

日志文件



Answer 2:

如果您使用log4j的,你可以设置你的log4j.properties文件如下,这将同时显示原生SQL查询和任何参数:

log4j.rootLogger=WARN, CONSOLE

log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
log4j.appender.CONSOLE.layout.ConversionPattern=%-5p %t %d{ISO8601} %l - %m%n

log4j.category.openjpa.jdbc.SQL=TRACE


Answer 3:

要配置Open JPA的Log4J的,你需要做的持久性XML以下

开放JPA配置{'属性名=” openJpa.Log”值=” log4j的”'}

Log4j属性开放JPA CONFIGS

log4j.logger.openjpa.Query = TRACE log4j.logger.openjpa.jdbc.SQL = TRACE

http://openjpa.apache.org/builds/1.0.1/apache-openjpa-1.0.1/docs/manual/ref_guide_logging_log4j.html



Answer 4:

您好我想添加运行persistance.xml文件

<?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="EHS_PU">
        <jta-data-source>mysqlDataSource</jta-data-source>
        <class>com.ap.entity.EHSDo</class>
        <class>com.ap.entity.EventDo</class>
        <properties>
            <property name="openjpa.Log" value="log4j" />
            <property name="openjpa.ConnectionFactoryProperties" value="PrintParameters=true" />
        </properties>
    </persistence-unit>
</persistence>


Answer 5:

除了瑞克的答案,也有对用于非托管连接的连接工厂“openjpa.ConnectionFactory2Properties”属性。 (在这里更多的细节: https://openjpa.apache.org/builds/1.2.3/apache-openjpa/docs/ref_guide_conf_openjpa.html#openjpa.ConnectionFactory2Properties )



文章来源: How do I configure OpenJPA SQL logging?
标签: openjpa