Simple but good model for EJB

What do you offer as a good and practical, but simple template for solving with:

  • HTML + JSP (as presentation / presentation)
  • Servlets (controller, request, session processing)
  • EJB (persistence, business logic)
  • MySQL DB

And do I need to use my own DAO layer to save? I use JPA to save objects in my DB.

Should I cancel the business logic from my EJB? All online sources tell me different things and confuse me ...

+4
java design-patterns session-bean
Jun 03 '10 at 22:00
source share
3 answers

I would definitely put business logic in sessions without a Beans state. A beans stateless session is good because they capture transaction boundaries well. And it separates the View layer from the save level.

Make sure that the SSB methods are consistent with the small business goals that the user wants to achieve.

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

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

For long-term use, consider using Message Driven beans, which you start by sending a JMS message. This is a good way to do background processing that speeds up business logic faster, reduces transactions, and returns control to the end user faster.

+5
Jun 03 '10 at 22:13
source share

What do you offer as a good and practical, but simple template for solving with JSP / Servlets + EJB + MySQL

Use the MVC structure of your choice, Non-Beans Session for business logic and transaction management (prefer local interfaces if you don't need remote operations), Entities for persistence.

Add your EJBs wherever possible (if you use Java EE 6, that means anywhere, and you can also skip the interface).

And do I need to use my own DAO layer to save? I use JPA to save objects in my DB.

Some may say yes, I say no in most cases. EntityManager already implements the Domain Store , there is no need to protect it for the DAO for simple needs .

You can read the following resources to learn more about this:

Should I cancel the business logic from my EJB?

I would not. Put your business logic in a Beans session. EJB3 - POJO, they are easily verified, there is no need to delegate business logic to another level.

+5
Jun 03 '10 at 23:38
source share

Anno 2012 I would not recommend using Servlets and JSP as a presentation layer. It was all the rage in 2002, but it was ten years ago.

Today Java EE has an excellent JCF MVC framework. You are much better off using this instead. Most likely, you will want to get some widgets from the PrimeFaces component library, since all the standard ones are a bit basic. Also useful is the OmniFaces utility library.

Regarding DAO; don't go as far as directly using the entity manager in (JSF) that supports beans, but if you already use the service classes (transaction boundaries) for your business logic, using DAO can also be excessive.

There are some more small advantages of DAO, for example dao.findByName (...) looks a little clearer than loading a named query, setting a parameter and getting (one) result, but the cost is that you should maintain a separate DAO for each object, maybe in addition to some service.

+1
Nov 26 '12 at 9:35
source share



All Articles