我发现kotlin中的数字不可序列化.
Device.kt:
package test.domain
import javax.persistence.*
Entity public class Device {
public Id GeneratedValue var id: Long = -1
public var name: String = ""
...
}
Run Code Online (Sandbox Code Playgroud)
DeviceRestRepository.kt:
package test.domain
import org.springframework.data.repository.PagingAndSortingRepository
import org.springframework.data.repository.query.Param
import org.springframework.data.rest.core.annotation.RepositoryRestResource
RepositoryRestResource(collectionResourceRel = "device", path = "device")
public trait DeviceRestRepository : PagingAndSortingRepository<Device, Long?> {
public fun findByName(Param("name") name: String): List<Device>
}
Run Code Online (Sandbox Code Playgroud)
我尝试编译此代码时出错,因为kotlin.Long不是Serializable:
错误:(14,72)Kotlin:类型参数不在其范围内:应该是'java.io.Serializable?'的子类型
我尝试使用java.lang.Long时遇到同样的错误:
DeviceRestRepository.kt:
package test.domain
import org.springframework.data.repository.PagingAndSortingRepository
import org.springframework.data.repository.query.Param
import org.springframework.data.rest.core.annotation.RepositoryRestResource
RepositoryRestResource(collectionResourceRel = "device", path …Run Code Online (Sandbox Code Playgroud) 我在注释中有一些问题:
Entity Table(uniqueConstraints = array(UniqueConstraint(columnNames = array("key", "userid"))))
public class ...
Run Code Online (Sandbox Code Playgroud)
在这种情况下,我得到以下错误:
类型推断失败。预期的类型不匹配:找到:kotlin.Array必需:kotlin.String
uniqueConstraints = array(...)没有问题,但是Idea向我显示columnNames = array(...)中的错误
我使用hibernate-jpa-2.1-api-1.0.0.Final.jar
解决方法:我使用复合键(@ javax.persistence.IdClass)代替uniqueConstraints