DTodt
DTodt

Reputation: 380

JPA 2 Mapping inheritance Type JOINED or SINGLE?

I've a test case, that have three tables/classes (Language, Caption and CaptionLanguage).

The Language table stores the languages data.
The Caption table stores the caption index data.
The CaptionLanguage table stores the caption data per language.

MER

Which Inheritance type I can use to solve the problem?

If I set the "@DiscriminatorColumn(name="ID_LANG",discriminatorType=DiscriminatorType.Integer)",
with the "@Inheritance(strategy=InheritanceType.JOINED)", will work?
Without use the @DiscriminatorValue(value="Value")

Thanks!

Upvotes: 0

Views: 287

Answers (1)

Mikko Maunu
Mikko Maunu

Reputation: 42114

This does not look like issue that could be solved by inheritance. Despite name, CaptionLanguage is not subtype of Language - it is also not subtype of Caption.

Instead it looks like three entities with following characteristic:

  • one-to-many from Language to CaptionLanguage (and/or many-to-one inverse)
  • one-to-many from Caption to CaptionLanguage (and/or possibly many-to-one inverse)
  • many-to-one from Caption to parent Caption (and/or one-to-many inverse)
  • CaptionLanguage does have composite primary key, so @IdClass, or @EmbeddedId should be used.

Upvotes: 1

Related Questions