Pavel Bernshtam Pavel Bernshtam - 11 months ago 107
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 <:]
trait SamRecordRepo extends PagingAndSortingRepository[SamRecord2, Int] {

How can I solve this issue?

Answer Source

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