Yan.F
Yan.F

Reputation: 640

Using the same type discriminator for superclass and subclass in OpenJPA

I'm trying to replicate a behavior of hibernate using OpenJPA, i tried something like:

SuperClass:

@Entity
@Table(name = "A")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "TYPE")
@DiscriminatorValue("A")
public class A{...

SubClass:

@Entity
@DiscriminatorValue("A")
public class B extends A{..

that causes the exception indicting that two class cannot have the same discriminator.

Is there a solution for this by using only Annotations?

Upvotes: 1

Views: 701

Answers (1)

Neil Stockton
Neil Stockton

Reputation: 11531

So what you're saying is that you want to persist an object of type A and an object of type B and when they are retrieved then they are BOTH instantiated as instances of type A? so the B will no longer be a B!!

I can't find any situation where that would be considered a good idea. Any JPA implementation that imposes that all concrete types have a different discriminator value is doing the right thing. Consequently we can conclude that OpenJPA behaviour is as it should be, and "working around it" is a bad idea.

Upvotes: 1

Related Questions