0

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.

2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by johndoe444
1

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.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.