`

读书笔记:PO, VO的区别

阅读更多

PO即 Persistence Object
VO即 Value Object

一个vo就是一个普通的对象,对应到对象状态当中是transient, detached两种状态。

Transient - an object is transient if it has just been instantiated using the new operator, and it is not associated
with a Hibernate Session. It has no persistent representation in the database and no identifier value has
been assigned. Transient instances will be destroyed by the garbage collector if the application doesn't hold
a reference anymore. Use the Hibernate Session to make an object persistent (and let Hibernate take care of
the SQL statements that need to be executed for this transition).
• Detached - a detached instance is an object that has been persistent, but its Session has been closed. The
reference to the object is still valid, of course, and the detached instance might even be modified in this
state. A detached instance can be reattached to a new Session at a later point in time, making it (and all the
modifications) persistent again. This feature enables a programming model for long running units of work
that require user think-time. We call them application transactions, i.e. a unit of work from the point of
view of the user.

PO 即纳入Hibernate管理框架中的VO,对应对象的persistent状态。

• Persistent - a persistent instance has a representation in the database and an identifier value. It might just
have been saved or loaded, however, it is by definition in the scope of a Session. Hibernate will detect any
changes made to an object in persistent state and synchronize the state with the database when the unit of
work completes. Developers don't execute manual UPDATE statements, or DELETE statements when an object
should be made transient.

VO和PO的主要区别在于:
1。 VO是独立的Java Object。
2。PO是由Hibernate纳入其实体容器(Entity Map)的对象,它代表了与数
据库中某条记录对应的Hibernate实体,PO的变化在事务提交时将反应到实际数据库中。
如果一个PO与Session对应的实体容器中分离(如Session关闭后的PO),那么此时,它又会变成一个VO。

由PO、VO的概念,又引申出一些系统层次设计方面的问题。如在传统的MVC架构中,
位于Model层的PO,是否允许被传递到其他层面。由于PO的更新最终将被映射到实
际数据库中,如果PO在其他层面(如View层)发生了变动,那么可能会对Model
层造成意想不到的破坏。

分享到:
评论

相关推荐

    《深入浅出Hibernate》读书笔记

    Transient和Detached状态的对象统称为VO(Value Object),不被Hibernate管理,而Persistent对象被称为PO(PersistentObject),由Hibernate的实体管理容器管理,其变更会在事务提交时同步到数据库。 其次,实体...

    Struts2 技术内幕读书笔记(1)

    ### Struts2 技术内幕读书笔记(1) #### WEB开发浅谈 ##### 面向对象浅谈 面向对象编程(Object-Oriented Programming,OOP)是一种软件开发范式,它通过模拟现实世界中的对象及其交互来构建程序结构。这种编程...

    java完美笔记

    - **VO(ValueObject, POJO, TO, PO)类**: VO类用于数据传输和封装,确保不同层之间传递的对象是对象而非原始数据类型。VO类应遵循一定的规范,如与表名一致,实现Serializable接口以支持序列化,使用包装类代替...

    Struts、Spring、Hibernate&Ajax;学习笔记总结

    ### Struts、Spring、Hibernate&Ajax 学习笔记总结 #### Struts 部分 **Struts** 是 Java 开源框架中最早出现且最具影响力的框架之一,它出自 Apache 组织,是 Java Web 应用开发的标准之一。Struts 以 MVC(Model...

    01_开关电源设计-反激式开关电源变压器设计(数值计算).docx

    变压器铁芯的尺寸是根据输出功率 Po(W)来决定。一般情况下,输出功率越高,铁芯尺寸越大。 5. 初级绕组数 Np 的计算 初级绕组数 Np 可以通过公式计算出来: Np = √(Lp / (μ × Ae)) 其中,μ 是磁导率,Ae ...

    M8871M8871EV1.15W、超低EMI、带AB类D类切换、无.pdf

    4. 低THD+N,0.1%@ VDDP=VDDA=5.0V , RL=4Ω, Po=1W,音频输出非常纯净。 5. 独特的淡入淡出效果,体现出优异的噪声抑制性能。 6. 可选切换方式的AB类/D类切换功能,用户可以根据需要选择合适的切换方式。 7. 带低...

    Blog:充当日常笔记或者个人博客吧

    Nginx配置文件详解Linux 安装JenkinsJAVA 多线程详解java 多线程学习How to create a Hello World with IntelliJ and Aspect JJava各种对象(PO,BO,VO,DTO,POJO,DAO,Entity,JavaBean,JavaBeans)的区分Java finally...

    JavaEye论坛热点推荐_-_2009年10月_-_总第17期.pdf

    4. **Struts2中的VO(Value Object)和PO(Plain Old Java Object)**:在MVC框架中,VO和PO用于数据传输和持久化。文章讨论了在Struts2中如何使用这两种对象,以及它们在业务逻辑层和表示层之间的作用。 5. **性能...

Global site tag (gtag.js) - Google Analytics