hi,

In this example:

public void init() throws ServletException {
        bookDB = (BookDBAO) getServletContext()
                                .getAttribute("bookDB");

        if (bookDB == null) {
            throw new UnavailableException("Couldn't get database.");
        }
    }

As it is not instantiating the BookDBAO instance and the connection with entity manager is done in the constructor:

public class BookDBAO {
    private ArrayList books;
    private EntityManager em;

    public BookDBAO(EntityManagerFactory emf) throws Exception {
        em = emf.createEntityManager();

        try {
        } catch (Exception ex) {
            throw new Exception(
                    "Couldn't open connection to database: " + ex.getMessage());
        }
    }

The where and how is this BookDBAO being instantiated? Thanks.

Search the codebase for "new BookDBAO(" ? But ideally, since you are retrieving the DAO from teh servlet context, the instantiation should have happened in the class which ServletContextListener. Look into your web.xml if you have any listener tags and search in those classes.

bien, bien. I found ContextListener class to instantiate BookDBDAO.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.