1

I'm trying to implement a inheritence relationship between JPA entities.

Borrowing the example from: http://openjpa.apache.org/builds/1.0.2/apache-openjpa-1.0.2/docs/manual/jpa_overview_mapping_discrim.html

@Entity
@Table(name="SUB", schema="CNTRCT")
@DiscriminatorColumn(name="KIND", discriminatorType=DiscriminatorType.INTEGER)
public abstract class Subscription {
          ...
}

@Entity(name="Lifetime")
@DiscriminatorValue("2")
public class LifetimeSubscription
    extends Subscription {
    ...
}
}

@Entity(name="Trial")
@DiscriminatorValue("3")
public class TrialSubscription
    extends Subscription {
    ...
}

What I need to be able to do is have an additional entity that catches the rest, something like:

  @Entity(name="WildCard")
    @DiscriminatorValue(^[23])
    public class WildSubscription
        extends Subscription {
        ...
    }

Where if it does not match LifetimeSubscription or TrialSubscription it will match WildSubscription. It actually makes a bit more sense if you think of it where the wild is the superclass, and if there is not a more concrete implementation that fits, use the superclass.

Anyone know of a method of doing this?

Thanks!

Link
  • 45
  • 1
  • 5
  • Another example is http://stackoverflow.com/q/2713025/187817 only there is a catch-all action defined – Link Dec 23 '11 at 04:06

1 Answers1

1

The JPA API allows only plain values here, and for a reason: discriminator values are mapped to SQL WHERE:

SELECT ... WHERE kind = 1 

If you could specify regular expressions here, it wouldn't be transferable to SQL, as it does not support such constructs.

MaDa
  • 10,511
  • 9
  • 46
  • 84