Hibernate学习笔记1 -- VO与PO

来源:互联网 发布:如何用ppt制作销售网络 编辑:程序博客网 时间:2024/03/29 13:28
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 160x600, 创建于 08-4-23MSDN */google_ad_slot = "4367022601";google_ad_width = 160;google_ad_height = 600;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
O/R Mapping -- Object Relational Mapping(对象关系映射)的缩写。通俗点讲,就是将对象与关系数据绑定,用对象来表示关系数据。如图:

                                              

VO -- Value Object 值对象。PO -- Persisent Object 持久对象。

它们的基本形式和写法如下:

public class User {    private String id;    private String name;    public VOid setId(String argId) {        this.id = argId;    }    public String getId() {        return this.id;    }    public VOid setName(String argName) {        this.name = argName;    }    public String getName() {        return this.Name;    }}

 

虽然它们的形式与写法基本相同,但意义却大不相同。1.VO是用new关键字创建,由GC回收的。   PO是向数据库中添加新数据时创建,删除数据库中数据时删除的。并且它只能存活在一个数据库连接中,当连接断开时,将被销毁。2.VO是值对象,精确点讲它是业务对象,是存活在业务层的,是业务逻辑使用的,它存活的目的就是为数据提供一个生存的地方。   PO是有状态的,每个属性代表其当前的状态。它是物理数据的对象表示。使用它,可以使我们的程序与物理数据解耦,并且可以简化对象数据与物理数据之间的转换。3.VO的属性是根据当前业务的不同而不同的,也就是说,它的每一个属性都一一对应当前业务逻辑所需要的数据的名称。   PO的属性是跟数据库表的字段一一对应的。

<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 160x600, 创建于 08-4-23MSDN */google_ad_slot = "4367022601";google_ad_width = 160;google_ad_height = 600;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
原创粉丝点击