[Article] Author: robbin Time: 2004-11-19 Source: hibernate Editor: Ark
[Documentation] In Struts Hibernate this structure, there should not be passed directly from the PO generated by Hibernate to JSP, whether he is iterator, or List, this is a design error
[text]
In the Struts Hibernate structure, you should not pass the PO generated by Hibernate directly to JSP, whether he is iterator, or List, this is a design error. I will talk about the data representation of each layer in the J2EE architecture: the data representation of the web layer is FormBean, data from the HTML Form Post business layer is indicated by the VO persistence layer, and its data is derived from the database. Data of the persistence layer represents, for example, CMP. In a specified J2EE architecture, data representation of different layers should be limited to the layer, and should not spread to other layers, which can reduce the interlayer coupling, improve the maintenanceability and scalability of the J2EE architecture. For example, the logic of the Web layer has been modified, then only the structure of the FORMBEAN does not need to touch the code modification of the business layer and the persistent layer. Similarly, when the database table has been adjusted, only the persistence layer data is required without the need to touch the business layer code and the web layer code. However, due to the powerful function of Hibernate, such as dynamically generating PO, PO's state management can be detached from Session so that the PO is fully acting as Vo, so we will consolidate the PO and VO, which is collectively referred to as PO. First talk about the significant difference between ActionformBean and PO of persistence: Actionformbean and Po are almost different, so many people simply use ActionformBean to act as PO, so ActionFormBean from JSP page to servlet control Go to the business layer, then pass through the persistence layer, and finally mapped to the database table. It's really a bit! But in complex applications, ActionFormBean and PO are separated, they are not possible. ActionformBean is a corresponding one of the Form form inside the web, what is the element in the form, what is the property in Bean. And the PO and database table correspond, so if the database table does not modify, the PO will not modify. If the page process and database table field correspondence, how can you use ACTIONFORMBEAN to replace PO? For example, the user registration page requires the basic information of the registered user, so the HTML Form contains the basic information properties, so you need an actionformbean to correspond to (Note: Yes, each correspondence), each bean property corresponds to a text box Or choose the box. And what is the user's lasting object? What is his attributes and what is the significant difference between Actionformbean? He will have some collection attributes that are not available, such as users' permissions attributes, user group properties, user posts, etc. It is also possible that there are three attributes in ActionFormBean, namely the user's first name, Middle Name, Last Name, and a Name object property in my user's persistent object. Suppose my registration page is originally as long as you provide first name, then ActionFormbean later, I will provide you with the full name, you have to change ActionFormbean, add two properties. But this time PO should not be modified, because the database has not been changed.