728x90
반응형
Problem
com.mysql.cj.jdbc.exceptions.MysqlDataTruncation: Data truncation: Data too long for column 'weather_detail' at row 1
at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:104) ~[mysql-connector-j-8.3.0.jar:8.3.0]
at com.mysql.cj.jdbc.ClientPreparedStatement.executeInternal(ClientPreparedStatement.java:912) ~[mysql-connector-j-8.3.0.jar:8.3.0]
at com.mysql.cj.jdbc.ClientPreparedStatement.executeUpdateInternal(ClientPreparedStatement.java:1054) ~[mysql-connector-j-8.3.0.jar:8.3.0]
at com.mysql.cj.jdbc.ClientPreparedStatement.executeUpdateInternal(ClientPreparedStatement.java:1003) ~[mysql-connector-j-8.3.0.jar:8.3.0]
at com.mysql.cj.jdbc.ClientPreparedStatement.executeLargeUpdate(ClientPreparedStatement.java:1312) ~[mysql-connector-j-8.3.0.jar:8.3.0]
at com.mysql.cj.jdbc.ClientPreparedStatement.executeUpdate(ClientPreparedStatement.java:988) ~[mysql-connector-j-8.3.0.jar:8.3.0]
at com.zaxxer.hikari.pool.ProxyPreparedStatement.executeUpdate(ProxyPreparedStatement.java:61) ~[HikariCP-5.0.1.jar:na]
MySQL 데이터베이스에 날씨정보 WeatherDetail를 JPA를 이용해 넣는 과정에서 문제가 발생하였다. JPA에서 문자열 필드에 대해 별도의 길이 제약을 주지 않을 경우 MySQL의 VARCHAR 타입의 최대 길이인 255자로 간주된다고 한다. 255자를 넘는 문자열일 경우 해당 에러를 일으키게 된다.
Solution
위 문제를 해결하기 위해 여러 해결방안을 정리해봤다.
1. 컬럼 길이 조정
@Column(length = 1000)
@JsonProperty("iscs")
private String weatherDetail;
2. VarChar 타입을 이용
@Column(columnDefinition = "VARCHAR(1000)")
@JsonProperty("iscs")
private String weatherDetail;
3. Text 타입 사용
@Column(columnDefinition = "TEXT")
@JsonProperty("iscs")
private String weatherDetail;
4. String 대신 Clob 사용
@Lob
@JsonProperty("iscs")
private String weatherDetail;
728x90
반응형
'ERROR' 카테고리의 다른 글
[ERROR/에러] Null value was assigned to a property ~ of primitive type (0) | 2024.03.28 |
---|---|
[ERROR/에러] Unknown integral data type for ids : java.lang.String (0) | 2024.01.23 |
[ERROR/에러] 카프카와 주키퍼 실행 에러 "입력 줄이 너무 깁니다. 명령 구문이 올바르지 않습니다." (0) | 2024.01.19 |
[ERROR/에러] APACHE KAFKA 아파치 카프카 실행 에러 (0) | 2024.01.19 |