----- Original Message -----
Sent: Thursday, July 26, 2001 11:20
AM
Subject: Re: [castor-dev] JSP &
Castor with session beans and lazy loading
I'm not sure if this is what you mean or if will solve your
problem, but have you tried retaining the database object using JNDI instead
of the session context ?
I have created an initialisation servlet that stores a JDO object in the
JNDI context as follows:
(You will need to obtain "jndi.jar" , "rmiregistry.jar", and
"providerutil.jar" from the Sun website).
import javax.naming.*;
import org.exolab.castor.jdo.*;
JDO jdo, jdo2;
Database db;
String contextFactory = "com.sun.jndi.rmi.registry.RegistryContextFactory";
// Load the mapping from the specified file, and Open up the
// database for read/write access
jdo = new JDO();
jdo.setConfiguration(getClass().getResource("database.xml").toString());
jdo.setDatabaseName( "test" );
//create the RMI registry
once on port 1099 (default);
new
sun.rmi.registry.RegistryImpl(1099);
// create the JNDI Context
Context ctx = new InitialContext();
ctx.addToEnvironment(javax.naming.Context.INITIAL_CONTEXT_FACTORY,
contextFactory);
//Bind the JDO the JNDI context
ctx.rebind("TestJDO",jdo);
Subsequent JSPs/Servlets can
then retrieve the JDO object and get a database object reference via the
following code:
// create the JNDI Context
Context ctx = new InitialContext();
ctx.addToEnvironment(javax.naming.Context.INITIAL_CONTEXT_FACTORY,
contextFactory);
//retreive the database from JNDI as a test
jdo2 =
(JDO)ctx.lookup("TestJDO");
db= jdo2.getDatabase();
Hope this helps.
Graeme
"Roberto M. Camps" wrote:
I've made a JSP application with castor. I
have a design problem, I don't know what to do when I have a session object
(which will be instantiated in one JSP page and stay in memory on another
JSP pages throught the http servlet Session object) and that object has one
or more lazy loading collection attribute/s.If I commit and close the database castor object at
the first JSP, then on the other JSPs there will be an error when I try to
get a lazy loading attribute. So I guess I will need to retain the same
database castor object for all the JSPs pages until the object with lazy
loading attributes is no longer needed (or the session
expires).What do you think
about the best solution for that? Thanks. Robert.