运行-time 在 scala 中使用异常时出错

Run-time Error while using anorm in scala

我尝试使用异常从数据库加载一些数据。但是我遇到了以下运行时错误

java.lang.RuntimeException: ColumnName(locations.Ref,Some(Ref))

这是我的模型class

package models
import play.api.db._
import play.api.Play.current

import anorm._
import anorm.SqlParser._

import scala.language.postfixOps
import scala.collection.mutable.ListBuffer

    case class Location(id: Int, name: String,ref:String,isactive:Int)


        object Location {

            /**
            * Parse a Location from a ResultSet
            */
            val loc = {
                get[Int]("Locations.Id") ~
                get[String]("Locations.Name")~
                get[String]("Locations.Ref")~
                get[Int]("Locations.Active") map {
                case id~name~ref~isactive => Location(id, name,ref,isactive)
                }
            }


             //Get All Locations from DB
              def findAllLocations():List[Location] = DB.withConnection { implicit c =>
                   SQL("SELECT Id,Name,Ref,Active from Locations").as(Location.loc *)
              }


}

这是我的 table

我找到了解决方案

我已经更改了代码,将 get[String]("Locations.Ref") 替换为 get[Option[String]]("Locations.Ref")

val loc = {
   get[Int]("Locations.Id") ~
   get[String]("Locations.Name")~
   get[Option[String]]("Locations.Ref")~
   get[Int]("Locations.Active") map {
   case id~name~ref~isactive => Location(id, name,ref,isactive)
   }
}

并将大小写 class 更改为 ref:Stringref:Option[String]

 case class Location(id: Int, name: String,ref:Option[String],isactive:Int)