0

I have a problem. I have a parent DAO:

public abstract class ParentDAO<T> {
    @PersistenceContext
    private EntityManager entityManager;

    public EntityManager getEntityManager() {
        return entityManager;
    }

    public void setEntityManager(EntityManager entityManager) {
        this.entityManager = entityManager;
    }

    private EntityManager em() {
        if (entityManager == null)
            throw new IllegalStateException("The entity manager is not set");

        return entityManager;
    }
}

from which extends another children DAOs. When I want to do some operation with children entity in children DAO, I must get EntityManager object from parent class or change the entityManager object declaration to protected which is bad OOP design. Is there another way to do this? Because when I have 100 DAO children's then I must get the entityManager from parent DAO for every new children.

Ladislav Mrnka
  • 360,892
  • 59
  • 660
  • 670
pierre tautou
  • 807
  • 2
  • 20
  • 37
  • I guess this question needs serious retagging but I don't know what tags are needed. The code is probably Java and Entity framework is .NET technology. – Ladislav Mrnka Mar 12 '11 at 22:42

1 Answers1

0

yes incase you are using spring, you can just use "parent" attribute to give the base bean id.... so create one base bean object in this case entity manager and add it as parent in ur subclassed bean declarations.... look for extends + parent in spring bean declaration.

srikanth N
  • 29
  • 3