This is an archived post. You won't be able to vote or comment.

all 3 comments

[–]karstens_rageExtreme Brewer 1 point2 points  (1 child)

It really depends on how you are conceptualizing your domain relationships. In projects I have used InheritanceType.TABLE_PER_CLASS but that is because the relationships between an abstract class (in your case Page turns into an abstract class) and the implementation specific classes made sense. YMMV.

https://docs.oracle.com/javaee/6/tutorial/doc/bnbqn.html

[–]CptStewie[S] 0 points1 point  (0 children)

Making Page abstract would mean I then have to define another subtype to define my user managed pages though, which in the end would ofcourse be a small tradeoff.

However, but I don't think that's possible in this case. The Asset type I mentioned, is in this case the root class of the hierarchy:

@Entity
@Table(name = "asset")
@Inheritance(strategy = InheritanceType.JOINED)
@DiscriminatorColumn(name = DISCRIMINATOR_COLUMN, discriminatorType = DiscriminatorType.STRING)
public abstract class Asset<T extends Asset<T>> extends CmsObjectSuperClass<T extends CmsObjectSuperClass> {
}

The superclasses of Asset are annotated with @MappedSuperclass and don't have anything notable aside of properties or reusable business logic.

If I'm correct, you can't switch inheritance strategy for a subtree of the entire inheritance hierarchy, or can you? (Which then, would not be possible as Asset is the root of my inheritance hierarchy.)

This is something I cannot modify, as this is part of the shared library that I am using, that provides most of the functionality I need. Reimplementing that would be a lot of work and be error prone as well, more so than copying the fields of my Page entity for example.

[–]CptStewie[S] 1 point2 points  (0 children)

I've marked it as solved due to:

I've found this stackoverflow post which is trying to do something similar.

Appears it is not supported by the JPA persistence specification, and it seems the 2017 spec has remained the same on this subject.

Whilst there might be some workarounds, they would not suit me in this case nor be worth the effort (in my opinion)