"Hibernate learning"--orm (iv) re-understanding of entity inheritance

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.