in the credit office, to do the breach of faith, the blacklist of this piece of time, the original needs to look at, and then began to design entities, this piece is the same information, most of the design of an entity, and with a status identified is a breach of faith, or the blacklist.
In the subsequent changes, especially inconvenient, every time you modify this piece, this will be a problem. That is to say, each time you need your own entity to maintain your state. But if we pull this state out, it becomes our public to maintain these "states", which greatly simplifies our work, and we only need to maintain the information of the basic table. This is a single-table inheritance.
Code:
Parent class:
@Entity (name= "Company") @Inheritance (strategy=inheritancetype.single_table) @DiscriminatorColumn (name= "type", discriminatortype=discriminatortype.string) public class Company { base field }
Sub-class:
@Entity @discriminatorvalue (value= "Oncreaditcompany") public class Oncreaditcompany extends company {}
Single-table inheritance is a large table that includes all the properties of the parent class, the subclass, and the Type to distinguish which subclass. Single-table inheritance, although several entity classes are written, has a clear hierarchy between classes and classes, and more object-oriented advantages. Compared to the one we designed to maintain with a state field, it is more convenient to operate.
There are pros and cons, and we have to weigh that the entity inheritance is not always applicable in all cases. However, the entity inheritance can not be considered, if it is a large number of database tables, access to data will have a large number of related table operations, inefficient.
"Hibernate learning"--orm (iv) re-understanding of entity inheritance