简单但很好的EJB模式 [英] Simple but good pattern for EJB

查看:145
本文介绍了简单但很好的EJB模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




  • HTML + JSP(作为视图/

  • Servlet(控制器,请求,会话处理)

  • EJB(持久性,商业)

  • MySQL DB



是否有必要使用自己的DAO层来进行持久化?我使用JPA来保存对象到我的数据库。我应该从我的EJB中撤销业务逻辑吗?



所有在线消息来源告诉我不同​​的事情,让我感到困惑...

解决方案

我肯定会把业务逻辑放在无状态会话Bean中。无状态会话bean很好,因为它们很好地捕获事务边界。并且它将View层与持久化层分离。



请注意,SSB的方法对应于用户希望实现的小型业务目标。

$另一点是,您必须确保您返回的数据具有对象树中的所有数据,并且不依赖于延迟加载来获取其余的数据,因为这会导致所有类型的



尽可能远离有状态会话Bean:它们是坏消息,是Web应用程序上下文中的一个破坏概念。



对于长时间运行的事情,请考虑使用通过发送JMS消息触发的消息驱动Bean。这些是进行后台处理的一种很好的方式,可以更快地释放业务逻辑,保持事务更短,更快地为最终用户返回控制。


What would you suggest as a good and practical but simple pattern for a solution with:

  • HTML + JSP (as a view/presentation)
  • Servlets (controller, request, session-handling)
  • EJB (persistence, businesslogic)
  • MySQL DB

And is it necessary to use an own layer of DAO for persistence? I use JPA to persist objects to my DB.

Should I withdraw business logic from my EJB? All online sources tell me different things and confuses me...

解决方案

I would definitely put the business logic in Stateless Session Beans. Stateless session beans are nice as they nicely capture the transaction boundaries. And it decouples the View layer from the persistence layer.

Take care that the methods of the SSB correspond to small business goals the user wants to achieve.

Another point is that you must be sure that the data you return has all data in the object tree and that you do not rely on lazy loading to get the rest, because this causes all kind of problems.

Stay as far away as possible from Stateful Session Beans : they are bad news and are a broken concept in the context of a web application.

For long running things, consider using Message Driven Beans which you trigger by sending a JMS message. These are a nice way to do background processing which frees the business logic faster, keeps transactions shorter and returns control to the end user faster.

这篇关于简单但很好的EJB模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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