层模型对象是否在层间传递? [英] Is domain model object passing between layers overhead?

查看:96
本文介绍了层模型对象是否在层间传递?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究一个使用hibernate和spring的项目。 Hibernate被封装在一个DAO层中,DAO层也有相应的服务层,还有为请求和JSP页面映射的控制器。我被告知不要在这些层之间传递对象(Controllers< - > Service< - > DAO),因为这是性能开销。一个特定的实例是当我需要更新域对象(ORM类)中的布尔值时,我编写了一个方法,该方法在服务层和DAO层之间传递了域对象,并告诉我传递对象ID和特定的布尔值值,并在图层中编写单独的方法。这是正确的吗?我觉得这样做会使使用ORM工具(Hibernate)的许多优点失效。我想这是错的吗?任何建议和见解将是有用的....

I am working on a project that uses hibernate and spring. Hibernate is encapsulated in a DAO layer and the DAO layer has corresponding service layer as well, theres also the controllers that is mapped for requests and JSP pages. I was told not to pass objects between these layers (Controllers <-> Service <-> DAO) as it is performance overhead. One particular instance was when I needed to update a boolean value in a domain object (ORM class), I wrote a method that passed the domain object between Service layer and DAO layer, and I was told to pass the object ID and the particular boolean value only and to write separate methods in the layers for that. Is this right? I feel doing so will invalidate many advantages of using an ORM tool (Hibernate). Am I wrong to think this? Any advice and insights will be useful....

推荐答案

你100%正确。这是可怕的建议。传递物体。这正是Hibernate设计的目标,正常传递对象的性能开销只是疯狂。除非您不了解应用程序的某些内容,否则请注意告知您的人的建议。

You're 100% right. That's terrible advice. Pass the objects around. It's exactly what Hibernate is designed for, and "performance overhead" for normal passing of objects is just crazy. Unless there's something about the app that you don't know, be wary of advice from the person that told you that.

这篇关于层模型对象是否在层间传递?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆