When I was developing, I read other people's code, and I found a note called @MappedSuperclass, based on the reason why I saw it for the first time, I looked up its meaning on the Internet, and I will summarize it here.
Conditions of use:
When we are working on a development project, we often use the operation of entity mapping to a database table, and at this time we often find that in several entity classes that we need to implicit,There are several common attributes such as number ID, created by, created time, modified, modified time, notes, etc。 In this case, we might think of abstracting these properties as a parent class, and then inheriting the parent class with a different entity class.
Then we canUsing @MappedSuperclass annotation, we can treat the entity class as the base class entity, which is not implicit to the database table, but the subclass entity that inherits it will automatically scan the implicit attributes of the base class entity and add it to the corresponding database table of the subclass entity.
Usage environment:
1.@MappedSuperclass annotations are used on top of the parent class to identify the parent class
A class identified 2.@MappedSuperclass indicates that it cannot be mapped to a database table because it is not a complete entity class, but it has properties that can be implicit in the database table used by its subclass
3.@MappedSuperclass can no longer have @Entity or @Table annotations
|