Jaime Bravo wrote:
1. DAO is a pattern and not only the artifact.
Yes, but DAO is an integration tier pattern. Based on the DAO pattern definition on Core J2EE Pattern, Use a Data Access Object (DAO) to abstract and encapsulate all access to the data source. The DAO manages the connection with the data source to obtain and store data.
Jaime Bravo wrote:
2. On the other side, SLSB is an artifact and not the service tier, itself. So without problems, an SLSB could be in integration tier.
I think the idea of injecting EntityManager into SB is kind of mixing business tier and integration tier. The boundary of each tier is not clear any more. The major benefits of EJB container are security, transaction management. So it's best for business tier. DAO layer should be able to site outside of EJB container. Probably you want to re-use DAO component in other project deployed outside of EJB container.
DAO pattern should provide unified interface for any kind of resources. It doesn't make much sense to wrap any other resource accessing code inside SLSB. Such as LDAP access, Web service client etc.
Jaime Bravo wrote:
But actually look up a dependency from inside the DAO class is not a good practice, because you're creating a dependency with the lookup mechanism and details about the same one. And this fact adds another responsability to the DAO class, that is: find its dependencies. So the class becomes less cohesive. For example if you change the JNDI name for the dependendy then....you know. So Dependency Injection pattern is the winner against the Service Locator pattern.
Before EJB container can specify other classed inside DI context, I'd rather use other DI provider to manage dependencies in DAO layer.
4. "if you create DAO from SLSB, then you need to manage transaction attributes for DAO methods. Good practice is you should only declare transaction from Service tier.". Transactions like security is a cross-cutting concern so it could be present in any tier(including presentation, bussiness, integration and resources tiers of course)
For example JMS operations can be transacted and, WS supports transaction throught the OASIS specs and another standards.
Jaime Bravo wrote:
5. "What's more, if you create DAO from SLSB, that means, client can probably skip other service tier wrapper SLSB to directly call those DAO SLSBs. " You can prevent that situation. Take a look to this code:
Client could be the upper tier running inside same container. "Local" wouldn't avoid those clients directly access SLSB DAOs.