5

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

Robert
  • 1,487
  • 1
  • 14
  • 26
  • Do you have something else in scope that has a === defined? For example, scalaz has a typesafe equals ===. – Taylor Leese Apr 15 '13 at 03:11
  • Hi @TaylorLeese, I've just added the two imports I have in my BaseDao class to the question. With those two imports, my concrete implementations of the Dao classes work fine (i.e. the === operator is able to be used with an Int property and an Int argument) – Robert Apr 15 '13 at 04:56
  • An answer can be found here: https://groups.google.com/forum/?fromgroups=#!topic/squeryl/CiBatiSnIug – jcern Apr 15 '13 at 23:36

1 Answers1

0

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.

Robin Green
  • 32,079
  • 16
  • 104
  • 187