Hi, I'm pretty much new to Spring & Hibernate. In our team, we are building a web application using Struts 2 for the presentation layer, with Spring 3 and Hibernate 3 (with Annotations) underneath. We are still debating on whether to use DAOs or not and Session
's or EntityManager
's for CRUD operations. Setting aside the question of which is better than the other, I ran into another problem using EntityManager
.
My goal is to create an abstract (generic) Service
which will expose 4 basic operations: save, delete, find by ID and find all by class. Other services will inherit from this and just implement custom finds or updates (this may change in the future). Problem is, I'm unsure where to put the annotated EntityManager
. I understand that if I call save() in a service from my Action
, i.e. Bob, which inherits the save()
from the Person parent Service
, the system will fail to inject the EntityManager
because the Service Person has not been called and the @PersistenceContext
annotation was not parsed.
Is there a way around this problem? I'd like to use inheritance for my services because that would reduce the amount of code needed for simple operations.