Pavel Bernshtam Pavel Bernshtam - 1 month ago 27
Scala Question

Scala: Int id in Spring Data Repository

I'm trying to create Spring Data Mongo repository using Scala.
My object has Int id, so I my repository looks like

trait SamRecordRepo extends PagingAndSortingRepository[SamRecord, Int] {
}


This code does not compile, because scala Int does not extend Serializable:

Error:(10, 29) type arguments [com.cgen.SamRecord2,Int] do not conform to trait PagingAndSortingRepository's type parameter bounds [T,ID <: java.io.Serializable]
trait SamRecordRepo extends PagingAndSortingRepository[SamRecord2, Int] {


How can I solve this issue?

Answer

Maybe use an Integer instead? java.lang.Integer extends Serializable.