i'm studying entity cache.
(kotlin, spring, jpa, hazelcast as second cache <= environment)
in data class, if i cache this entity, it makes this error(class com.exercise.Test cannot be cast to class java.io.Serializable)
@Cacheable
@Cache(
usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE,
region = "Test"
)
@Entity
@Table(name = "the_test")
data class Test(
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
val id: Int = 0,
val locale: Locale,
val testJson: TestJson
)
enum class Locale {
JP,
KO,
EN,
;
}
typealias TestJson = TestData
data class TestData(
val name: String = "",
val type: String = "TestData",
val children: List<TTestData> = emptyList()
)
data class TTestData(
val name: String,
val type: String = "TTestData",
val isShow: Boolean,
val payload: Optional<Any>,
val children: Optional<List<TestData>>
)
but after i added to each nested TestJson like below, then it works.
typealias TestJson = TestData
data class TestData(
val name: String = "",
val type: String = "TestData",
val children: List<TTestData> = emptyList()
):Serializable
data class TTestData(
val name: String,
val type: String = "TTestData",
val canBeRecentMenu: Boolean,
val payload: Optional<Any>,
val children: Optional<List<TestData>>
):Serializable
i still don't get it why it works fine and why serializable needed like this.
can anyone explain this?
- because of hazelcast built-in serialization, entity didn't need
implements serializable? - enum class didn't need implements because of kotlin serialization?
- why each testjson need serialization? how do i know that it needs
implements serializable? i thought nested class is also class so hazelcast built-in serialization works too, but it didn't. it makes me confuse