JPA 2.0 (logging and tracing through) with Glassfi

2019-02-16 14:06发布

问题:

I am using JPA 2.0 (EclipseLink provider) with Glassfish v3.0.1 and NetBeans 6.9.1 and am NOT able to see the queries and other logging information from JPA 2.0. Essentially I want to be able to see all the SQL statements which are being generated by JPA and other related debugging information...

Has anyone successfully been able to configure the logging to provide such feedback? I've tried several things to no avail...

Any help would be greatly appreciated.

Thanks much.

回答1:

What eventually had done the trick for me was using:

<property name="eclipselink.logging.logger"
     value="org.eclipse.persistence.logging.DefaultSessionLog"/>
in conjunction with your recommended tag of:
<property name="eclipselink.logging.level" value="FINE" />
This allowed me to see the relevant JPA logs which in NetBeans output window. This also worked in Eclipse. The output was sent do the console window an intermingled with the server's output which was exactly what I wanted.



回答2:

You must configure logging level in persistence.xml file.

Example:

<persistence-unit name="MY_POOL_NAME" transaction-type="JTA">
  <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
    <jta-data-source>MY_JTA_SOURCE</jta-data-source>
    <properties>
        <property name="eclipselink.logging.level" value="FINE" />
        <property name="eclipselink.target-server" value="SunAS9"/>
    </properties>
  </persistence-unit>

Log Levels:
OFF
SEVERE
WARNING
INFO
CONFIG - Use this for Production
FINE
FINER
FINEST
More info: http://wiki.eclipse.org/EclipseLink/Examples/JPA/Logging

All the queries would be printed in the domain server.log file.