1

I done a git clone of spring data - jpa.

I search a way when I running test to see generated query.

robert trudel
  • 5,283
  • 17
  • 72
  • 124
  • [See this Answer](https://stackoverflow.com/questions/30118683/how-to-log-sql-statements-in-spring-boot) – aorticDefiance Aug 01 '17 at 17:42
  • good try but it's for spring boot... so no really working for spring-data.... – robert trudel Aug 01 '17 at 17:48
  • You just need to set the hibernate properties and the log level of your specific logging framework, same principle applies. The loggers you want turned on are: `org.hibernate.type=TRACE` for bind values `org.hibernate.SQL=DEBUG` for SQL You can also set the property `hibernate.show_sql=true` All depends on how you configuring the session factory in spring data. – aorticDefiance Aug 01 '17 at 18:06
  • Found the answer here as the accepted answer didnt work in my application.yml https://stackoverflow.com/questions/30118683/how-can-i-log-sql-statements-in-spring-boot – Norbert Jul 25 '23 at 21:03

1 Answers1

1

I have tested with the followings:

  • Edit the /src/test/resources/META-INF/persistence.xml file and add the following two lines in the <properties> section of cdi, cdi-52, merchant, metadata and metadata-52 persistence-unit.

    <property name="hibernate.show_sql" value="true"/>
    <property name="hibernate.format_sql" value="true"/>
    
  • Add the below line in the <properties> section of the same file's persistent-unit named metadata_oj

    <property name="openjpa.Log" value="SQL=Trace" />
    
  • Edit the src/test/resources/eclipselink.xml file and rewrite below section as :

    <util:properties id="jpaProperties">
        <prop key="javax.persistence.jdbc.driver">org.hsqldb.jdbcDriver</prop>
        <prop key="javax.persistence.jdbc.url">jdbc:hsqldb:mem:hades</prop>
        <prop key="javax.persistence.jdbc.user">sa</prop>
        <prop key="javax.persistence.jdbc.password"></prop>
        <prop key="javax.persistence.ddl-generation">create-tables</prop>
    
        <prop key="eclipselink.logging.level.sql">FINE</prop>
        <prop key="eclipselink.logging.parameters">true</prop>
    </util:properties>
    
  • Also, edit the below section of src/test/resources/openjpa.xml file as:

    <util:properties id="jpaProperties">
        <prop key="openjpa.Log">SQL=Trace</prop>
    </util:properties>
    

Then, you can run mvn test to test the project and check whether you can see the generated queries or not.

sunkuet02
  • 2,376
  • 1
  • 26
  • 33