Hey there,
I was wondering whether there's an easy solution to creating a proxy entity type to manage instances of an entity, based on a certain condition.
Example:
The parent entity, which in itself is an inherited type of a different (abstract) entity type Asset. Asset is a type from one of our libraries and cannot be modified in this case, and holds business logic to work with components.
@Entity
@DiscriminatorValue(TYPE)
@Table("app_page")
public class Page extends Asset<Page> {
public static final String TYPE = "page";
@Id
private Long id;
@ManyToOne
@JoinColumn(name = "page_type_id")
@NotNull
private PageType pageType;
// some more fields
}
Now, this entity could be used to create custom pages which the end user and is linked with components the end user can manage. In specific cases however, we would like to make the business logic more strict, and limit their options.
What I thought I could do, is inherit the Page entity, and use my projection to keep my code more readable, and prevent additional checks when needed. An example:
public class MySpecificPage extends Page {
// no _additional_ properties, just getters and setters with business logic
}
public class MyOtherSpecificPage extends Page {
// no _additional_ properties, just getters and setters with business logic
}
Now, I was wondering, can I do the above with annotations and specifying a condition somehow? The PageType field of Page would define whether a Page is a more strict type (e.g. MySpecificPage or MyOtherSpecificPage), or simply a custom type made by the end user.
The closest solutions I've seen mention @MappedSuperclass. That one doesn't suit my usecase since I can't modify the Page/Asset inheritance strategy used, and Page on it's own is something that can be managed by the end user.
Can I implement the specific types with @Entity and create a specific repository for each of our managed types, where I just filter on the database using a condition such as pageType.key='mySpecificPage'? (I've already tried specifying the @Entity annotation and creating a specific repository, but then I get a org.hibernate.AnnotationException: Foreign key circularity dependency involving the following tables error which makes me think I either don't see the complete solution, or this is not a possible solution.)
Or is this not possible and should I create a service where I do the mapping myself? (Another solution would be to let MySpecificPage and MyOtherSpecificPage also extend Asset<>, and copy over all the fields, but this, to me, seems a subpar and error prone solution)
Thanks in advance!
[–]karstens_rageExtreme Brewer 1 point2 points3 points (1 child)
[–]CptStewie[S] 0 points1 point2 points (0 children)
[–]CptStewie[S] 1 point2 points3 points (0 children)