Originally posted by Srikanth Nittala:
Mine is a classic JEE application with this flow ( JSF + EJB + Oracle) on OC4J.
That's a robust environment. Also consider using JPA over Toplink. Is it OC4J 10g 10.1.3.3? Be aware there are a few bugs on OC4J in regard of EJB3, but nothing that would compromise the application.
Originally posted by Srikanth Nittala:
In the EJB3 books and Sun's JEE5 tutorial i ve read so far, they always have an EJB ( Session bean) thats filled with business logic and calls to DB via Entity Manager(injecting it) .
But is it a good practice to have business logic and DB calls in EJB that way? Now if you add service class(using Spring) or an DAO ( that does DB calls for each entity) you lose the power of injections and container-managed Entity managers. And I dont see the use of Spring services here as i think it is an overhead code for a simple flows like CRUD.
So in short i guess my question is " Is it ok to have all the business logic in session facade EJB itself? Isnt the facade EJB supposed to be neat and clean just doing security and transactions? What are the best practices for JEE architecture?
It's not good practice to keep business logic withing EJB. Regarding where to place the business logic, I would recommend you to place them in POJOs realizing, thus, the Application Service J2EE pattern. EJB is a thin application layer. EJB is rather a way to expose services to the outside world. You may inject the EntityManager within EJB and pass it as an argument of the Application Service POJO. Take a look at the J2EE Core Patterns 2nd Ed. Study the Application Service Pattern.
You don't need DAOs if you're using App Service + JPA, because JPA is itself a domain store. You may want to use DAOs when you're encapsulating access to legacy systems either through using raw JDBC directly or emulating a screen scraper. You may want to combine App Service + JPA for trivial stuff and App Service + DAO to run stored procedures, for example.
Don't forget to set up TWO connection pools. One for the JPA other for the DAOs itself.
Regards