JavaEE6 DAO: Should it be @Stateless or @ApplicationScoped?

前端 未结 3 1368
误落风尘
误落风尘 2020-12-08 03:21

I\'m currently creating an EJB3 Data Access Class to handle all database operations in my Java EE 6-application. Now, since Java EE 6 provides the new ApplicationScope

3条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-08 03:40

    @Pascal: In my opinion my DAO isn't "responsible" of transaction or security, as the container manages these services. I'm just annotating the methods in my DAO (only for security, as transactions are handled automatically). Are annotations already "responsibility"?

    Okay so you make me re-think about my design. Hope its okay and not too off-topic, but maybe it helps - this is how i'm using JEE6 today:

    • JSF accesses a CDI Bean,
    • the CDI Bean accesses the DAO-EJB which does the "business logic"
    • so currently my only "business logic" is doing CRUD, later i'll add some other EJBs for critical tasks like asynchronous methods or Timer Services.
    • my DAO is generic and uses the JPA2 Criteria Query to do typesafe queries (no strings at all)
    • I know that i don't need a DAO for persist/update/remove (too simple), but i need it for my queries; so i just put them together

    Is something wrong with that approach?

提交回复
热议问题