DAOFactory class name via JNDI


EJB programming & troubleshooting: DAOFactory class name via JNDI

  1. DAOFactory class name via JNDI (1 messages)

    I used the DAO pattern in my design to separate database specific code from the entity EJBs. Furthermore I have DAOFactory classes for each particular database (currently only MySQL) that create DAO instances for that database. Finally I wanted to configure the beans to read the class name of the concrete DAOFactory implementation from JNDI.

    What I want to ask is if there is a way how to make such <env-entry>:


    available(visible) to all my beans.

    Currently I am able to assign it just to particular bean and so I have to repeat it in the EJB deployment descriptor for each bean that needs to instantiate the concrete DAOFactory. And this is not way to go I guess.

    Of course one solution would be to create some DAOFactoryGetter (meta factory ;o)) as a session bean and the concrete class name put in its name space. But is it really neccessary?

    Thank you for your answers,

  2. DAOFactory class name via JNDI[ Go to top ]

    I don't think the meta-factory (as you call it) approach is necessary. You can add a getDAO(Class) method to your service locator, and that's it.
    What you CAN'T do (due to EJB spec) is having a global env-entry. The good news is that you can user a super-class to all your entities with a method that gets the DAO from the service locator, and use XDoclet to generate the env-entry from that super class. So, you write the metadata in the super class and XDoclet includes the entry for each entity EJB.

    Cheers and happy coding,