Hi Marino,

what version of OJB do you use?

Versions 0.94 - 0.96 does bound database instance with the
thread. Here Implementation class was a singleton (see OJB.java)

With the lastest version 0.97 and the CVS head it should be
possible to do that. Here Implementation was no longer a
singleton and the database was associated with the Implementation
instance.

Please post your further experience to the list, this could
be useful for others and me (i did this changes (version 0.96 to 0.97)
to make usecases like yours possible)

regards,
Armin


----- Original Message -----
From: "Marino Tudor" <[EMAIL PROTECTED]>
To: "Ojb-User" <[EMAIL PROTECTED]>
Sent: Tuesday, October 15, 2002 5:01 PM
Subject: Database instance not found in multithreaded environments?


> Hi,
>
> The idea was to put Implementation and Database
> in session context using a ServletContext Event Listener Class
> and after that to allow all users to get those object from session
scope.
>
> But it seams that Database is null for all threads except thread where
db
> was
> opened, so errors occur every time I tried to start Transaction
> (tx.begin())??
>
> Is there any solution for this or I have to
> open my db for every thread (user) again and again???
>
>
> The following code has been used:
>
> *** ServletContext Event Listener Class************
> public void contextInitialized(ServletContextEvent event){
>      Implementation odmg = OJB.getInstance();
>      Database db = odmg.newDatabase();
>      db.open("repository.xml", Database.OPEN_READ_WRITE);
>
>      context.setAttribute(IConstants.OJB_SETTINGS, odmg);
>      context.setAttribute(IConstants.OJB_DB, db);
> }
>
> *** ServletContext Event Listener Class END  ************
>
> *** Client  Class************
> public void blahBlah () {
>      Implementation odmg =
>         (Implementation)
context.getAttribute(IConstants.OJB_SETTINGS);
>      Database db =
>         (Database) context.getAttribute(IConstants.OJB_DB);
>         // tried also Database db = odmg.newDatabase(null);
>
>      Transaction tx = odmg.newTransaction();
>      tx.begin();
>      // BANG ??????????????????
>
> }
>
> *** Client Class END  ************
>
> Marino Tudor
>
>
>
>
>
>
>
>
>
> --
> To unsubscribe, e-mail:
<mailto:[EMAIL PROTECTED]>
> For additional commands, e-mail:
<mailto:[EMAIL PROTECTED]>
>
>
>


--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to