Entity classes are a concept that is widely used in Java software development. But there is little on the web to tell exactly what it is. In this issue I am going to talk about what is an entity class.
First, the intuitive look:
An entity class is a class that has a set and get methods. Entity classes are often associated with databases and the like (so-called persistent layer data). This connection is established by a framework such as hibernate.
Second, the definition (more jerky difficult to understand):
Entity classes are primarily a category of data management and business logic processing, and their primary responsibility for differentiating entity classes in the analysis phase is to store and manage information inside the system, and it can have behavior or even complex behavior, but these behaviors must be closely related to the entity objects it represents.
This passage looks less understood and should be combined with the role of the entity class:
The role of entity classes (requires an object-oriented bit of basic knowledge):
The entity class is a carrier.
Now the design is almost a table is equal to a class within the business. A record (a typical row of data) is an object, and a column in a row is a property of that object.
So when we manipulate a table, such as changing the information of the table, we can define an object in the foreground and then assign its corresponding property to the background.
So that the background can get all the values of this object-not a single attribute when the argument passed, as long as the object of this class is passed, that is, as long as a parameter is good. The benefits are self-evident.
And this foreground object to the background database contact, we are by the framework, configuration files to configure the implementation, very convenient and fast. You do not need to manually program your implementation.
In short, (in most cases) the entity class is what the database corresponds to in Java code.
Finally, excerpt a little bit of Javapeak's experience of using entity classes greatly:
First, the name of the entity class should be the same as the name of the database table.
Second, the entity class should implement the Java.io.Serializable interface.
Third, the entity class should have a non-parametric construction method.
Four, the entity class should have a parameter (all parameters) of the construction method.
The entity class has attributes and methods, the property corresponds to the field of the table in the database, and the method mainly includes getter and setter method.
Six, the entity class should also have a property serialversionuid.
For example: private static final long serialversionuid = -6125297654796395674l;
The property is generally private type, the method is the public type, for the database automatically generated ID field corresponding to the
The set method for the property is private.
What is the role of entity classes and entity classes in Java