I'm using OJB in Tomcat and I couldn't seem to locate any information about
where and when to open and close the Database object. I assumed that
OJB.getInstance would return a reference to a singleton object so that if I
created a new database in one place that would be sufficient. I wrote a
ContextIntializer which is a class that has a contextInitialized method that
gets called on webapp deployment and put the following code in it:
-----
Implementation odmg = OJB.getInstance();
database = odmg.newDatabase();
try {
database.open(null, Database.OPEN_READ_WRITE);
}
catch (ODMGException e) {
log.fatal("Error initializing the database", e);
throw new InitializationException("Error initializing the database", e);
}
------
I then put then put the following code in a Struts action:
-----
Implementation odmg = OJB.getInstance();
Transaction tx = odmg.newTransaction();
-----
I know that the datbase is opened because of the log messages I print out,
but later when the action is called I get:
org.odmg.DatabaseClosedException: Database is NULL, must have a DB in order
to create a transaction
Where and when should I be opening and closing the database. I assumed I
would only have to open it once on application startup and close it on
shutdown. Is this assumption incorrect? If so what are the performance
consequences of opening and closing the Database object?
Eric
DISCLAIMER: The information contained in this e-mail is, unless otherwise
indicated, confidential and is intended solely for the use of the named
addressee. Access, copying or re-use of the e-mail or any information
contained therein by any other person is not authorized. If you are not the
intended recipient please notify us immediately by returning the e-mail to
the originator.