Java (Po,vo,bo,dao,dto,pojo) explanation

Source: Internet
Author: User
Tags one table
POJO (Plain ordinary Java object) simple, irregular Java objects
Simple Java objects (Plain old Java Objects) are actually ordinary JavaBeans, using pojo names to avoid confusion with EJBS, and the short name is more straightforward. Some of these properties and their getter setter methods can sometimes be used as either the value object or the DTO (Data Transform object). Of course, if you have a simple operation attribute is also OK, but do not allow a business method, You can't carry a connection or something like that.
Description: Can be converted into PO, DTO, VO.
1, Pojo after the persistence of ==〉po
(During the runtime, the cglib dynamic of the hibernate converts Pojo to Po,po and adds some properties and methods for managing the Pojo state of the database relative to entity. PO for programmer is completely transparent, because it is the runtime generated PO, so you can support incremental compilation, incremental debugging. )
2, Pojo transmission process of ==〉dto
3, Pojo used as the presentation layer ==〉vo
Both PO and VO should belong to it.

The PO (Persistant object) Persistent object 1, sometimes referred to as the data object, corresponds to the entity in the database, which can be simply considered a PO corresponding to a record in the database.
2, in the Hibernate persistence Framework is closely related to the insert/delet operation.
3, the PO should not contain any operation of the database.

The VO (Value object) Value object 1, the main corresponding page display (Web page/SWT, swing Interface) data object.
2, can correspond with the table, also can not, this according to the business needs.
Note: In struts, using actionform to do VO requires a conversion because the PO is Object oriented and Actionform is corresponding to view, to synthesize a actionform of the attributes to be displayed by several po. You can use the Beanutils copy method.

BO (business object) business object
Encapsulation business logic is an object (can include multiple po, usually need to convert Bo to Po, in order to persist data, on the contrary, the PO from DB needs to be converted into Bo to be used at the business level).
There are three main concepts about BO
1. Contains only the attributes of the business object;
2. Include only business methods;
3, both are included.
In practical use, it is not important to think which concept is right, the key is to apply the actual application of the need for their own projects.

DTO (TO): Data Transfer Object Data transfer objects
1. It should not contain business logic when it needs to be transmitted across processes or remotely.
2, for example, a table has 100 fields, then the corresponding PO has 100 attributes (in most cases, the data in the DTO from more than one table). But the view layer only needs to display 10 fields, and there is no need to pass the entire PO object to the client, so we can use the DTO with only these 10 attributes to transfer the data to the client, which does not expose the server-side table structure. When the client is reached, if the object is used to display the interface, then its identity becomes VO.

DAO (data Access Object)
is a sun-standard Java EE design pattern in which an interface is a DAO, which negatively operates on a persistent layer. Provides interfaces for the business layer. This object is used to access the database. Commonly used in conjunction with PO, DAO contains a variety of database operation methods. Through its method, combine the PO to carry on the related operation to the database.
1, mainly used to encapsulate access to db (Crud operations).

2, by receiving the business layer of data, the Pojo lasting into a PO.

The difference between Po and VO:

The O/R Mapping is an abbreviation of the Object relational Mapping (objects relational mapping). In layman's terms, the object is bound to the relational database, and the object is used to represent the relational data. In the world of O ' mapping, there are two basic and important things to understand, that is, Vo,po.
VO, Value object, PO, persistent object (Persisent object), which consists of a set of the Get and set methods of a group of properties and properties. Structurally, they are not the same place. But in terms of their meaning and nature, they are completely different.
1. Vo is created with the New keyword and is recycled by GC.
The PO is created when new data is added to the database, and is removed when the data in the database is deleted. And it can only survive in a database connection, the disconnect is destroyed.
2. Vo is a value object, it is a business object, it is in the business layer, is the business logic used, it is the purpose of survival for the data to provide a place to live.
The PO is stateful, and each attribute represents its current state. It is the object representation of the physical data. With it, we can decouple our programs from physical data and simplify the transformation between the object data and the physical data.
3. The properties of VO vary according to the current business, meaning that each of its attributes corresponds to the name of the data required by the current business logic.
The property of the PO corresponds to the field one by one of the database table.

The difference between a persistent object (POJO) and a PO:

The persistent object must actually correspond to the entity in the database, so it differs from the Pojo. For example, Pojo is created by new and collected by GC. However, the persistent object was created by the Insert database and deleted by the database delete. Basically, the persistence object lifecycle is closely related to the database. In addition, persistent objects can often only exist in a database connection, connnection closed, persistent objects do not exist, and Pojo as long as not be GC recovery, always exist.

Because there are so many differences, the persistent object Po (persistentobject) is definitely different from Pojo in code, and at least the PO will add some properties and methods for managing the entity state of the database relative to Pojo. And Orm pursuit of the goal is to PO in use as much as possible and pojo consistent, for programmers, they can use the PO as a pojo, but not feel the existence of PO.

Reference URL:



Related Article

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: 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.