2
 hibernate session to list conversion
 Compilation Error occured when java converted into scala..!!   

错误:类型不匹配;找到:java.util.List[?0] 其中需要类型 ?0:scala.collection.immutable.List[com.scala.entity.User]

   Code:     def getAllUsers(): List[User] = {
          return getSession().createQuery("from User where reslut='false'").list()
           }
4

2 回答 2

3
    def getAllUsers(): List[User] = {
    val objList = getSession().createQuery("from User where isDelete = 'false'").list()
    objList.asInstanceOf[List[User]]
于 2013-03-30T04:51:51.297 回答
2

可能是使用 scala.collection.JavaConverters 的简单方法:

import scala.collection.JavaConverters._

def getAllUsers = getSession().createQuery("from User where reslut='false'").list().asScala.toList.map(_.asInstanceOf[User])
于 2013-03-28T12:46:48.990 回答