Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NotSerializableException 이슈 #143

Open
daadaadaah opened this issue Jul 15, 2023 · 0 comments
Open

NotSerializableException 이슈 #143

daadaadaah opened this issue Jul 15, 2023 · 0 comments

Comments

@daadaadaah
Copy link
Collaborator

daadaadaah commented Jul 15, 2023

What

에러 내용

org.apache.ibatis.type.TypeException: Could not set parameters for mapping: ParameterMapping{property='originalOrderQuantityForPartialOrder', mode=IN, javaType=class java.lang.Object, jdbcType=null, numericScale=null, resultMapId='null', jdbcTypeName='null', expression='null'}. Cause: org.apache.ibatis.type.TypeException: Error setting non null for parameter #6 with JdbcType null . Try setting a different JdbcType for this parameter or a different configuration property. Cause: java.sql.SQLException: Invalid argument value: java.io.NotSerializableException // 🎯
	... 88 common frames omitted
Caused by: org.apache.ibatis.type.TypeException: Error setting non null for parameter #6 with JdbcType null . Try setting a different JdbcType for this parameter or a different configuration property. Cause: java.sql.SQLException: Invalid argument value: java.io.NotSerializableException // 🎯
	... 91 common frames omitted
Caused by: com.mysql.cj.exceptions.WrongArgumentException: Invalid argument value: java.io.NotSerializableException
	... 94 common frames omitted
Caused by: java.io.NotSerializableException: java.util.Optional // 🎯
	... 96 common frames omitted
2023-07-15T21:30:19.059+09:00  WARN 87194 --- [nio-8080-exec-1] .m.m.a.ExceptionHandlerExceptionResolver : Resolved [org.mybatis.spring.MyBatisSystemException]

에러 해석

  • originalOrderQuantityForPartialOrder 필드를 직렬화 하지 못해서 발생한 이슈이다.
public class OrderFormSavedInAdvanceEntity {
    // ... 생략
    private final Optional<Integer> originalOrderQuantityForPartialOrder;
    // ... 생략
}

Why

  • Optional의 경우, 반환값이 없음을 나타내는 것이 주 목적이다.
  • 그렇다 보니, Java에서 Optional 클래스는 Serializable 인터페이스를 구현하지 않아, Optional 인스턴스를 직렬화할 수 없다.
  • 따라서, Optional 필드를 가진 클래스를 직렬화하려고 시도하면, 위와 같이 java.io.NotSerializableException 예외가 발생한다.
  • 실제, Optional의 경우, 필드에 사용하는 것을 금지한다.

How

  • Optional<Integer> 대신 Integer 사용하기

Reference

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant