title: how to disallow pattern matching on certain classes in scala
body: <p>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 <a href="http://oletraveler.com/2011/04/20/20/" rel="nofollow">http://oletraveler.com/2011/04/20/20/</a></p>
  
  <p>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.</p>
  
  <p>For example:</p>
  
  <pre><code>@Entity
  @Inheritance(strategy = InheritanceType.JOINED)
  class PaymentSource
  
  @Entity
  class CreditCard
  
  @Entity User {
    var paymentSources: java.util.ArrayList
  }
  
  user.paymentSources.map(_ match {
    case cc: CreditCard =&gt; println("oops") // &lt;- this should error
  })
  </code></pre>
  
  <p>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.</p>
  
  <p>Any thoughs?</p>