9 Replies Latest reply on Oct 31, 2008 6:51 AM by Kamil Demecki

    Using EntityManager in a abstract super class

    Mohammad Norouzi Novice


      we have an interface say, DataAccessManipulator. since the method save(), delete() and update() are common for all the DAO classes we have created a GeneralDataAccessManipulator as an abstract class in which those methods have been implemented using EntityManager:

      public abstract class GeneralDataAccessManipulator implements DataAccessManipulator {
       private EntityManager entityManager;
       public void delete(Object entity) {
       if (!entityManager.contains(entity)) {
       entity = doMerge(entity);
       try {
       } catch (Exception e) {
      //rest of the code...

      now this class and many others are located in a jar file namely common-j2ee.jar

      because there are many project in the company that are developing at the same time we shared this recent jar file for all other projects.

      the problem is in our application we have to specify the unitName for the PersistenceContext and in another application this name may be different
      and because in the GeneralDataAccessManipulator we didn't specify unitName the app won't be deployed and of course if we set it, other apps will encounter the problem

      my question is if we can set that unitName in a way according to the applciation persistence unit.

      I've read something about @EJBS on class declaration but didn't understand it really. Can we make use of that?

      I am thinking of giving a specific unitName to the @PersistenceContext defined in abstract class an then inject the EM inside my app and set it as the name specified above in the SB I am using. Is this possible?

      thanks for your help