I am wondering if there are any special solutions or software design patterns for the following scenario. I have similar attributes for my Hibernate-Mapping-Classes, like isEnabled, isDetelable, dateCreated, lastModified, ... . I don't want to repeat the property definition in each class, instead define them once, and add the property to the classes I want. For example ClassA can have isEnabled and dateCreated, ClassB can have dateCreated and isDeletable, ClassC can have isEnabled, isDetelable, lastModified and so on.
Asked
Active
Viewed 238 times
0
-
Possibly related to: http://stackoverflow.com/questions/5257921/hibernate-how-override-an-attribute-from-mapped-super-class – Manu Nov 16 '15 at 14:44
-
Searching hibernate inheritance gives proper answers for this... Solution: `@MappedSuperClass`. – Luiggi Mendoza Nov 16 '15 at 14:56
-
This question has nothing to do with Hibernate - it is a classic software design question. And all possible solutions are supported by Hibernate: Composition, Aggregation and Inheritance. – Tobias Liefke Nov 16 '15 at 15:17
1 Answers
0
One option is to use the @MappedSuperclass
annotation to create a superclass for your entities which contains the fields you want. Another solution is to use an @Embeddable
class that contains the fields and use the @Embedded
annotation to add them to only specific entities, in which case you don't need to extend a super entity.

Kayaman
- 72,141
- 5
- 83
- 121