I want to know how to output query parameter binding using Hibernate.
I tried using the org.hibernate.type.descriptor.sql
and org.hibernate.type.sql
property but it didn't work.
environment version
- spring boot 2.7.14
- Hibernate 5.6.15
build.gradle
plugins {
id 'java'
id 'org.springframework.boot' version '2.7.14-SNAPSHOT'
id 'io.spring.dependency-management' version '1.0.15.RELEASE'
}
group = 'com.study'
version = '0.0.1-SNAPSHOT'
java {
sourceCompatibility = '11'
}
repositories {
mavenCentral()
maven { url 'https://repo.spring.io/milestone' }
maven { url 'https://repo.spring.io/snapshot' }
}
dependencies {
implementation 'com.oracle.database.jdbc:ojdbc8:21.9.0.0'
implementation 'org.springframework.boot:spring-boot-starter-jdbc'
implementation 'org.mybatis.spring.boot:mybatis-spring-boot-starter:3.0.0'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
// Lombok
implementation 'org.projectlombok:lombok'
annotationProcessor('org.projectlombok:lombok')
implementation 'org.springframework.boot:spring-boot-starter'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
tasks.named('test') {
useJUnitPlatform()
}
- application.properties
# JPA Setting
spring.jpa.hibernate.ddl-auto=none
spring.jpa.generate-ddl=false
spring.jpa.show-sql=true
spring.jpa.database=oracle
spring.jpa.database-platform=org.hibernate.dialect.OracleDialect
# hibernate logging info
spring.jpa.properties.hibernate.show_sql=true
spring.jpa.properties.hibernate.format_sql=true
spring.jpa.properties.hibernate.use_sql_comments=true
# Logging Setting
logging.level.org.hibernate.SQL=info
logging.level.org.hibernate.type.descriptor.sql=trace
- test code
@Test
@DisplayName("log test")
void test13() {
EntityManagerFactory emf = Persistence.createEntityManagerFactory("ch02");
EntityManager em = emf.createEntityManager();
EntityTransaction tx = em.getTransaction();
try {
Employee emp = new Employee();
emp.setName("aaa");
tx.begin();
em.persist(emp);
tx.commit();
} catch (Exception e) {
e.printStackTrace();
tx.rollback();
} finally {
em.close();
emf.close();
}
}
- test result
21:13:32.973 [Test worker] DEBUG org.hibernate.SQL -
insert
into
S_EMP
(DEPT_NAME, memo, name, salary, START_DATE, title, id)
values
(?, ?, ?, ?, ?, ?, ?)
Hibernate:
insert
into
S_EMP
(DEPT_NAME, memo, name, salary, START_DATE, title, id)
values
(?, ?, ?, ?, ?, ?, ?)
21:13:33.001 [Test worker] DEBUG org.hibernate.resource.jdbc.internal.LogicalConnectionManagedImpl - Initiating JDBC connection release from afterTransaction
21:13:33.002 [Test worker] DEBUG org.hibernate.resource.jdbc.internal.LogicalConnectionManagedImpl - Initiating JDBC connection release from afterTransaction
21:13:33.002 [Test worker] DEBUG org.hibernate.engine.jdbc.internal.JdbcCoordinatorImpl - HHH000420: Closing un-released batch
21:13:33.003 [Test worker] DEBUG org.hibernate.internal.SessionFactoryImpl - HHH000031: Closing
21:13:33.003 [Test worker] DEBUG org.hibernate.type.spi.TypeConfiguration$Scope - Un-scoping TypeConfiguration [org.hibernate.type.spi.TypeConfiguration$Scope@796c68bf] from SessionFactory [org.hibernate.internal.SessionFactoryImpl@3d620a1]
21:13:33.003 [Test worker] DEBUG org.hibernate.service.internal.AbstractServiceRegistryImpl - Implicitly destroying ServiceRegistry on de-registration of all child ServiceRegistries