slick元组数据超过22个错误解决

在使用Slick时遇到元组数据超出22个元素限制的错误,解决方案是引用slickless库。具体步骤包括导入slickless.jar,引入shapeless相关类如HList、::、HNil和Generic,然后进行数据库操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

xxx.scala:65: error: too many elements for tuple: 24, allowed: 22

实例:

import slick.lifted.Tag
import slick.jdbc.MySQLProfile.api._
import scala.concurrent.Await
import scala.concurrent.duration.Duration
import scala.collection.JavaConversions._
import java.util.List

case class Server(
                 id: Int,
                 serverCode: String,
                 imageHash: String,
                 name: String,
                 gender: String,
                 education: String,
                 birthday: String,
                 mobileTelephone: String,
                 otherTelephone: String,
                 identityCard: String,
                 politicalStatus: String,
                 nation: String,
                 agencyId : Int,
                 nativeProvinceId: Int,
                 nativeCityId: Int,
                 nativeCountyId: Int,
                 provinceId: Int,
                 cityId: Int,
                 countyId: Int,
                 address: String,
                 createDatetime: String,
                 identity: String,
                 isEnable: Boolean,
                 backup: String
                 )
class Servers(tag: Tag) extends Table[Server](tag, "servers") {
    def id = column[Int]("id", O.PrimaryKey, O.AutoInc, O.SqlType("int"))
    def serverCode = column[String]("server_code", O.Unique, O.Length(32), O.SqlType("char"))
    def imageHash = column[String]("imageHash", O.Length(32), O.Default("00000000000000000000000000000000"), O.SqlType("char"))
    def name = column[String]("name", O.Length(20), O.SqlType("varchar"))
    def gender = column[String]("gender", O.Length(4), O.SqlType("varchar"))
    def education = column[String]("education", O.Length(8), O.SqlType("varchar"))
    def birthday = column[String]("birthday", O.SqlType("datetime"))
    def mobileTelephone = column[String]("mobile_telephone", O.Length(16), O.SqlType("varchar"))
    def otherTelephone = column[String]("other_telephone", O.Length(32), O.SqlType("varchar"))
    def identityCard = column[String]("identity_card", O.Length(18), O.SqlType("char"))
    def politicalStatus = column[String]("political_status", O.Length(8), O.SqlType("varchar"))
    def nation = column[String]("nation", O.Length(12), O.SqlType("varchar"))
    def agencyId = column[Int]("agency_id")
    def nativeProvinceId = column[Int]("native_province")
    def nativeCityId = column[Int]("native_city")
    def nativeCountyId = column[Int]("native_county")
    def provinceId = column[Int]("province")
    def cityId = column[Int]("city")
    def countyId = column[Int]("county")
    def address = column[String]("address", O.Length(128), O.SqlType("varchar"))
    def createDatetime = column[String]("create_datetime", O.SqlType("datetime"))
    def identity = column[String]("identity", O.Length(16))
    def isEnable = column[Boolean]("is_enable")
    def backup = column[String]("backup", O.SqlType("text"))

    def * = (id, serverCode, imageHash, name, gender, education, birthday, mobileTelephone, otherTelephone, identityCard, politicalStatus,
    nation, agencyId, nativeProvinceId, nativeCityId, nativeCountyId, provinceId, cityId, countyId, address, createDatetime,identity,isEnable, backup) <> (Server.tupled, Server.unapply)

}

解决方法:https://github.com/underscoreio/slickless

1.导入入 slickless.jar  

2.引入类

importshapeless.{HList,::,HNil,Generic }

importslickless._

    3.

 def * = (id :: ... :: HNil).mappedWith(Generic[Server])




数据库操作实例

def getAll() : List[Demand_2] ={
   val result = Await.result(db.run(
     (for{
       d <- demands
       e <- employers
       if d.employerId === e.id
      } yield    (d.id :: d.employerId :: d.demandSource ::
       d.demandType :: d.serviceType :: d.level :: d.serviceStartTime ::
       d.serviceEndTime :: d.provinceId :: d.cityId :: d.countyId ::
       d.area :: d.address :: d.detail :: d.isEnable :: d.state :: d.serviceStartDate ::
       d.serviceEndDate :: d.createTime :: d.lastModifyTime :: d.longitude :: d.latitude ::
       e.name :: e.tel :: e.userNum :: HNil).mappedWith(Generic[Demand_2])
       ).result), Duration.Inf).toList

   return result;
}




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值