I'm being analizing your code... Well, I get my broker using

PersistenceBrokerFactory.defaultPersistenceBroker()

Have you tried to work with defaultPersistenceBroker()? I know that in some
release (I don't know what) things was changed in the way OJB is getting the
.xml based on this config... Then you can evolute to a
createPersistenceBroker after this is working...

Another point: you are declaring a object scoped broker in

    public class AccountUpdater extends Thread
    {
        private PersistenceBroker broker = null;

but in the run method, you are not filling in because you are declaring a
new try scoped broker:

           PersistenceBroker broker =
                 PersistenceBrokerFactory.createPersistenceBroker(new
PBKey("ActiveBill"));


You can test making in the following way:

public class AccountUpdater extends Thread
{
//    private PersistenceBroker broker = null; // This line is being removed
in favor of a parameter for retrieveAccountByNumber...

public void run()
    {
       try
        {
           PersistenceBroker broker =
                 PersistenceBrokerFactory.defaultPersistenceBroker();
           broker.beginTransaction();
           AccountInterface acc = retrieveAccountByNumber(broker, "1234");
           broker.commitTransaction();
        }
       catch (Exception e)
            {
              broker.abortTransaction();
              System.out.print(e.getMessage());
              e.printStackTrace();
             }
       finally {
         broker.close();
       }
      }


Don't forget to change the retrive... to use the parameter you are
sending...
Another point that could you check is use rc3 or download cvs HEAD to build
a "near rc4" bin. They are far stable than previous versions...

My2c,

Edson Richter

----- Original Message ----- 
From: "Bonnie MacKellar" <[EMAIL PROTECTED]>
To: "OJB Users List" <[EMAIL PROTECTED]>
Sent: Monday, July 07, 2003 5:36 PM
Subject: RE: Weblogic, threads, and startup errors


Well, that is precisely why I was trying this - to ensure that I have
no brokers spanning threads.

My code looks like this :

public class AccountUpdater extends Thread
{
    private PersistenceBroker broker = null;


public void run()
    {
       try
        {
           PersistenceBroker broker =
                 PersistenceBrokerFactory.createPersistenceBroker(new
PBKey("ActiveBill"));
           broker.beginTransaction();
           AccountInterface acc = retrieveAccountByNumber("1234");
           broker.commitTransaction();
        }
       catch (Exception e)
            {
              broker.abortTransaction();
              System.out.print(e.getMessage());
              e.printStackTrace();
             }
       finally {
         broker.close();
       }
      }

The exception is thrown right at the createPersistenceBroker step. If I run
this so that a new thread is not spawned, there is no problem. But if I
spawn a thread and then call this code, I get the exception.

The NULL error that you are having appear to me a problem to acquire the
broker (read "not find the asked config"). Using defaultPersistenceBroker
you will be acquiring the one defined in

Again, I need to do this in order to avoid long lived brokers.

Bonnie MacKellar
software engineer
Mobius Management Systems, Inc.
[EMAIL PROTECTED]


> -----Original Message-----
> From: Edson Carlos Ericksson Richter
> [mailto:[EMAIL PROTECTED]
> Sent: Monday, July 07, 2003 4:30 PM
> To: OJB Users List
> Subject: Re: Weblogic, threads, and startup errors
>
>
> I don't know about you, but I had all kind of strange errors
> working with
> long time broker lives...
>
> Now, I'm working as in mnemonic code:
>
> public void xyzStore( XYZObject o ) {
>   broker = getBroker();
>
>   try {
>       broker.store( o );
>   } catch() {
>   }finally {
>     broker.close(); // this guarantees no mistakes...
>   }
>
> }
>
> This guarantees that the broker object isn't spawned along
> threads... And my
> code works fine!
> Since the brokers are maintained in a pool, there is not pain
> in performance
> (AFAIK).
>
>
> Edson Richter
>
>
> ----- Original Message ----- 
> From: "Bonnie MacKellar" <[EMAIL PROTECTED]>
> To: "OJB Users List (E-mail)" <[EMAIL PROTECTED]>
> Sent: Monday, July 07, 2003 5:20 PM
> Subject: Weblogic, threads, and startup errors
>
>
> I posted a question on Thursday about a mysterious error I am
> getting when I
> try to obtain a broker in a thread spawned within my
> application. It was not
> answered, perhaps because of the holiday, or perhaps because
> no one else is
> doing what we are doing.
>
> We are running a servlet based application in Weblogic. I am
> using rc2 at
> the moment. As long as I obtain the broker in the main
> thread, there is no
> problem. But if I spawn a new thread and try to obtain the
> broker, I was
> getting obvious classpath problems - OJB.properties not
> found, and so forth.
>
> I explicitly placed the classpath info for the app in my
> Weblogic startup
> file (not good, but I will try anything right now). Doing
> this, it does find
> the OJB.properties file, but now I get another odd error :
>
> [BOOT] ERROR: The specified class
> "org.apache.ojb.broker.cache.ObjectCachePerBrokerImpl" does
> not implement
> the interface org.apache.ojb.broker.cache.ObjectCache, which is a
> requirement for the key "ObjectCacheClass". Using default class
> org.apache.ojb.broker.cache.ObjectCacheDefaultImpl
> java.lang.NullPointerException
>         at dbtests.AccountUpdater.run(AccountUpdater.java:68)
>
> Has anybody ever encountered this error before? Obviously,
> something goes
> hideously wrong with the configuration of OJB once threads
> get into the
> picture, but what? And again, I do not have this problem as
> long as the code
> to obtain the broker is situated in the main thread.
>
> thanks,
> Bonnie MacKellar
> software engineer
> Mobius Management Systems, Inc.
> [EMAIL PROTECTED]
>
>
>
>
> ---
> Outgoing mail is certified Virus Free.
> Checked by AVG anti-virus system (http://www.grisoft.com).
> Version: 6.0.497 / Virus Database: 296 - Release Date: 4/7/2003
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>



---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.497 / Virus Database: 296 - Release Date: 4/7/2003


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

Reply via email to