Robert
Robert

Reputation: 1507

value === is not a member of type parameter TKey (using Squeryl)

I'm trying to write a simple BaseDao class using the excellent squeryl ORM framework.

However I've come across a problem when using generic typed keys. I get a compile error when I try and use the '===' operator in my generic BaseDao class. The compile error is: value === is not a member of type parameter TKey

My dao class with its troublesome method is defined as:

import org.squeryl.PrimitiveTypeMode._
import org.squeryl._

abstract class BaseDao[TKey, T <: BaseEntity[TKey]](val table: Table[T]) {

  def delete(entity: T) : Boolean = {
    table.deleteWhere(record => record.id === entity.id) //This is where I get the compile error
  }
}

BaseEntity is defined as:

abstract class BaseEntity[TKey] extends KeyedEntity[TKey]

I import PrimitiveTypeMode in my Dao class too... My first though was that TKey needed to be constrained to whatever the === operator was constrained to, but on looking at the source, there doesn't seem to be any explicit constraints around the operator, so I'm a bit lost.

The operator is defined in the source of squeryl here: https://github.com/max-l/Squeryl/blob/master/src/main/scala/org/squeryl/dsl/TypedExpression.scala

Upvotes: 5

Views: 421

Answers (1)

Robin Green
Robin Green

Reputation: 33083

I don't think this can be done in Squeryl. Squeryl doesn't support generically-typed keys - it uses Java reflection to get their type, which is erased at runtime, and therefore thinks they are of type Object.

Upvotes: 0

Related Questions