Scala Pattern matching with hibernate proxies do not work with lists of inherited objects. To work around this, I wrap hibernate objects in case classes, see http://oletraveler.com/2011/04/20/20/
What I would like to accomplish is to throw a compile time error (preferrable) or runtime error if someone tries to match on an inherited hibernate entity.
For example:
@Entity
@Inheritance(strategy = InheritanceType.JOINED)
class PaymentSource
@Entity
class CreditCard
@Entity User {
var paymentSources: java.util.ArrayList
}
user.paymentSources.map(_ match {
case cc: CreditCard => println("oops") // <- this should error
})
I tried overriding unapply on CreditCard, but that didn't work since unnapply is only called when deconstructing the object, not just matching on the instance.
Any thoughs?