2012-05-24 173 views

回答

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

啓用記錄所有SQL語句,減去參數值。

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

啓用SQL參數的記錄。

Logging documentation

4

如果你使用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 
+0

您發佈的配置不會記錄SQL參數。 – Rick

+0

它實際上會記錄SQL參數。請看下面的例子的輸出:(?????,,,,) INSERT INTO TCATALOG(UIDPK,CATALOG_CODE,DEFAULT_LOCALE,MASTER,NAME) VALUES [PARAMS =(長)200001(字符串)catalog133835591682111,(字符串)en_US,(int)0,(String)測試目錄] – Templar

+1

不夠公平。這種行爲取決於您使用的OpenJPA版本。 @瞭解更多詳情 - https://issues.apache.org/jira/browse/OPENJPA-1678 – Rick

0

您好我想添加運行持久性。 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>