长类型不正确

osh*_*hai 0 hibernate primitive-types kotlin

我在 Hibernate 中有以下查询:

val em: EntityManager = ...
em.createQuery("SELECT id FROM Segment s WHERE $condition", Long::class.java)
val result = q.resultList
Run Code Online (Sandbox Code Playgroud)

运行它时,我收到以下错误:

Type specified for TypedQuery [long] is incompatible with query return type [class java.lang.Long]
Run Code Online (Sandbox Code Playgroud)

osh*_*hai 6

看起来被视为Long::class.java未装箱,应替换为Long::class.javaObjectType

工作代码是:

val em: EntityManager = ...
em.createQuery("SELECT id FROM Segment s WHERE $condition", Long::class.javaObjectType)
val result = q.resultList
Run Code Online (Sandbox Code Playgroud)