Reputation: 45
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!
Upvotes: 1
Views: 1029
Reputation: 10762
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.
Upvotes: 1