Online explanations of the differences between Po and VO:
"VO, Value Object",
PO, persistent objects (Persisent object), which consist of a set of get and set methods of a group of properties and properties. Hibernate the object that incorporates the entity container (Entity Map) that represents the hibernate entity corresponding to a record in the database, and the change in the PO will be reflected in the actual database when the transaction is committed. 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. (data directly on VO)
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. (Objects and data are separated but converted to each other)
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. (related to business data)
The property of the PO corresponds to the field one by one of the database table. (related to the database field data)
The PO object requires the implementation of a serialization interface.
”
I want to go deeper into the 2nd, that is, the PO is stateful, and each attribute represents its current state. It is the object representation of the physical data.
Vo is a value object, which is a business object precisely, and its purpose is to provide a place for the data to live.
Hibernate uses the PO class to manipulate the database as follows (EMP is the PO Class):
EMP emp = (EMP) session.load (Emp.class, "005");
The Emp.class statement means that after the EMP has been compiled into a. class file, the Emp.class method is used to get the class instance object representing the bytecode data of the EMP class from the Java virtual machine.
This means that the operation of the PO is hibernate to the compiled bytecode file, The bytecode. class file is encapsulated into the Hashtable by the class loader after the mapping file Emp.hbm.xml the data of the database, which is called "Vo is the object representation of the physical data" as described above. When a transaction is committed, The state of the memory is synchronized to the database by executing the SQL Inset,update,delete statement.
and Vo Class (BookInfo is Vo Class):
Public byte[] Getcover (BookInfo book) throws SQLException {
BookInfo Book1 = (BookInfo) sqlmap.queryforobject ("Getcover", book);
return Book1.getcover ();
}
Ibatis's operation of the Vo class is to bookinfo. java file operations, not to. class files, so Vo is at the business level, it is the business object, and the value changes with the logic changes.