๐ฉ์๋ฌ
2024-04-25T22:52:54.233+09:00 ERROR 21840 --- [core] [nio-8081-exec-3] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed: java.lang.IllegalStateException: Cannot set property id because no setter, no wither and it's not part of the persistence constructor public kpring.chat.chatroom.model.ChatRoom()] with root cause java.lang.IllegalStateException: Cannot set property id because no setter, no wither and it's not part of the persistence constructor public kpring.chat.chatroom.model.ChatRoom()
์ด๋ฐ ์๋ฌ๊ฐ ๋ด๋ค
โณ ํด๊ฒฐ
Model ์ id๋ฅผ val์์ var๋ก ๋ณ๊ฒฝํด์ค
@Id
val id: String? = null
→
@Id
var id: String? = null
@Document(collection = "chatrooms")
class ChatRoom(
var members : MutableList<String>
){
@Id
var id: String? = null
val createdAt: LocalDateTime = LocalDateTime.now()
fun getUsers(): MutableList<String>{
return members
}
fun addUsers(list : MutableList<String>){
members.addAll(list)
}
}
๐์์ธ
Kotlin์์ val๋ก ์ ์ธํ ์ Java์ final๋ก ๋ณํ๋๋๋ฐ
Spring Data 2.1๋ถํฐ immutable objects๋ฅผ ๋ ์ง์ํ๊ณ final์ ๋ ์ด์ ์ง์ํ์ง ์์ ๋ฐ์ํ๋ ๋ฌธ์ ์ด๋ค
์ฝ์ด๋ณด๋ฉด ์ข์ ๊ธ
https://www.geeksforgeeks.org/final-vs-immutability-java/
https://discuss.kotlinlang.org/t/kotlin-val-var-vs-java-final-advantage/22908