简体   繁体   English

Hibernate Model Objects作为VO对象

[英]Hibernate Model Objects as VO objects

Most of the time I get this advice not to use hibernate model objects as my Value Objects or UI Objects. 大多数时候,我得到这个建议,不要将hibernate模型对象用作我的Value Objects或UI Objects。 Will there be any issues if I use Hibernate model objects as VO objects or Form Objects in UI? 如果我将Hibernate模型对象用作UI中的VO对象或表单对象,是否会出现任何问题? If it is ok to use I can avoid copying values to and from the VO and model Objects. 如果可以使用,我可以避免在VO和模型对象之间复制值。

I think you're right, there are no issues with that. 我认为你是对的,没有问题。 It is a matter of context. 这是一个背景问题。

Hibernate model objects are simple POJOs with some metadata (annotations) attached to it. Hibernate模型对象是简单的POJO,附加了一些元数据(注释)。 At the persistence layer this metadata means something, but in the view layer it means nothing. 在持久层,这个元数据意味着什么,但在视图层中它没有任何意义。

This way in the view layer it acts as a VO, but in the persistence layer it acts as a model object, so it indeed eliminates the need for separate VOs. 这种方式在视图层中它充当VO,但在持久层中它充当模型对象,因此它确实消除了对单独的VO的需要。

This is the beauty of metadata. 这是元数据之美。

If you're concerned with the security of an object travelling from UI to database, this would be another subject. 如果您关心从UI到数据库的对象的安全性,这将是另一个主题。

There are various ways to ensure security, but basically it would be achieved by using proper authentication and authorization mechanisms, queries with parameters and/or Criteria API. 有多种方法可以确保安全性,但基本上可以通过使用适当的身份验证和授权机制,带参数的查询和/或Criteria API来实现。

For more info on that, please take a look at this and this . 有关这更多信息,请看一看这个这个

I hope it helps. 我希望它有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM