JPA 에서 MYSQL 또는 Maria DB 에 한글이 들어 있는 레코드를 삽입할 때 발생할 수 있는 오류 해결 방법
2024. 3. 17. 04:55ㆍJava/JPA
JPA 에서 MYSQL 또는 Maria DB 에 한글이 들어 있는 레코드를 삽입할 때 발생할 수 있는 오류 해결 방법
java.sql.SQLException: (conn=133) Illegal mix of collations (latin1_swedish_ci,IMPLICIT) and (utf8mb4_general_ci,COERCIBLE) for operation '='
at org.mariadb.jdbc.export.ExceptionFactory.createException(ExceptionFactory.java:306) ~[mariadb-java-client-3.3.2.jar:na]
// import org.hibernate.dialect.MySQL5InnoDBDialect;
// MySQL5InnoDBDialect 을 찾을 수 없을 때에는 MySQLDialect 으로 대체한다.
import org.hibernate.dialect.MySQLDialect;
public class CustomMysqlDialect extends MySQLDialect {
public String getTableTypeString() {
return " ENGINE=InnoDB DEFAULT CHARSET=utf8";
}
}
spring:
datasource:
driver-class-name: org.mariadb.jdbc.Driver
username: root
password: 12345
url: jdbc:mariadb://localhost:3306/myprojdb
thymeleaf:
cache: false
check-template: true
prefix: classpath:/templates/
suffix: .html
enabled: true
jpa:
hibernate:
ddl-auto: none
# ddl-auto: update
properties:
hibernate:
dialect: com.myproj.config.CustomMySqlDialect
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
storage_engine: innodb
show-sql: false
h2:
console:
enabled: true
logging:
level:
# hibernate 가 남기는 모든 로그가 debug모드로 설정
# jpa hibernate가 생성하는 sql이 로거를 통해서 찍히도록 하는 설정
org.hibernate.sql: debug
org.hibernate.type: trace # 실제 들어가는 파라미터값 찍어주는 설정
원본 문서 :