1

I have created a very basic spring boot app with spring data JPA and below is my application.properties file

The issues is : SQL statements are not logged in spring boot console in eclipse.

I have tried many options as mentioned at - How to print sql statements with values in spring boot JPA application.

But still no luck.

Can anybody please help here as what might be the issue here ?
pom.xml is also attached

application.properties:

spring.datasource.url=jdbc:h2:mem:testdb
spring.datasource.driverClassName=org.h2.Driver
spring.datasource.username=sa
spring.datasource.password=
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.H2Dialect

#to show sql
spring.jpa.properties.hibernate.show_sql=true
#formatting
spring.jpa.properties.hibernate.format_sql=true
#printing parameter values in order
logging.level.org.hibernate.type.descriptor.sql=trace

spring.h2.console.enabled=true
# default path: h2-console
spring.h2.console.path=/h2-ui

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.7.10</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.example</groupId>
    <artifactId>Tutorial</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>Tutorial</name>
    <description>Demo project for Spring Boot</description>
    <properties>
        <java.version>11</java.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-rest</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>
Atul
  • 1,560
  • 5
  • 30
  • 75
  • Does this answer your question? [How to log SQL statements with query param values in Spring Boot 3/Hibernate 6](https://stackoverflow.com/questions/74862254/how-to-log-sql-statements-with-query-param-values-in-spring-boot-3-hibernate-6) – Andrey B. Panfilov Apr 19 '23 at 12:58

2 Answers2

1

Could you please try to add spring.jpa.show-sql=true? It will print to console. See more details here.

Andrej Istomin
  • 2,527
  • 2
  • 15
  • 22
0

Can you please try this, it is working on my project <version>3.0.1</version>

    logging.level.org.hibernate.SQL=DEBUG
    logging.level.org.hibernate.type.description.sql.BasicBinder=TRACE
    spring.jpa.properties.hibernate.format_sql=true

WP7
  • 31
  • 1
  • 7