Ok, I forgot

Environment
OJB 0.9.5
MySQL 3.23.38-nt
Windows 2000
JDK 1.3.1

BrokerFactory does only return the DefaultBroker:
    public static PersistenceBroker getDefaultBroker() {
        PersistenceBroker broker = null;

        if (m_defaultBroker == null) {
            synchronized(PersistenceBrokerFactory.class) {
                if (m_defaultBroker == null) {
                    try {
                        m_defaultBroker =
PersistenceBrokerFactory.defaultPersistenceBroker();
                        broker = m_defaultBroker;

                    } catch (Throwable t) {
                        m_log.error("Error initializing the Default
PersistenceBroker.");
                    }
                }
            }
        } else {
            broker = m_defaultBroker;
        }

        return broker;
}

Hope that helps

bye
Thomas

> -----Urspr�ngliche Nachricht-----
> Von: Armin Waibel [mailto:[EMAIL PROTECTED]]
> Gesendet: Mittwoch, 4. September 2002 12:19
> An: OJB Users List; [EMAIL PROTECTED]
> Betreff: Re: TransactionNotInProgressException and AutoCommit Question
>
>
> Hi Thomas,
>
> which version of OJB do you use?
>
> I see in your code snip:
> ....
> try {
>             broker = BrokerFactory.getDefaultBroker();
>
>             broker.beginTransaction();
> ....
>
> Did you implement your own PersistenceBrokerFactory 'BrokerFactory'?
> What does BrokerFactory do?
>
> > I have debugged the code and the problem is broker.store(sel)
> > I'm currently using the DefaultSequenceMangerImpl which stores the MAX
> ID's
> > for each table in Object SequenceEntry, within the store-process a new
> > Identity is created for SequenceEntry with the construtor of Identity
>
> It's recommended to use the SequenceManagerHiLoImpl or in older versions
> the SequenceManagerHighLowImpl.
>
>
> regards,
> Armin
>
>
> ----- Original Message -----
> From: "Thomas Fahrmeyer" <[EMAIL PROTECTED]>
> To: "OJB Users List" <[EMAIL PROTECTED]>
> Sent: Wednesday, September 04, 2002 12:00 PM
> Subject: AW: TransactionNotInProgressException and AutoCommit Question
>
>
> > Hi,
> >
> > the complete Method is (and this is executed):
> >    protected boolean saveSelection(Selection sel, boolean
> asMarketingAction)
> > {
> >         boolean ok = false;
> >         PersistenceBroker broker = null;
> >
> >         try {
> >             broker = BrokerFactory.getDefaultBroker();
> >
> >             broker.beginTransaction();
> >
> >             Action action = null;
> >
> >
> >             broker.store(sel);
> >
> >             // Hack: ok state must be set after commit, but there is a
> >             // unresolved NotInTransactionException which have to be
> > considered.
> >             // Selection is saved anyhow
> >             ok = true;
> >
> >             // 7. commit transaction
> >             broker.commitTransaction();
> >             file://broker.close();
> >             ok = true;
> >         } catch (PersistenceBrokerException pbe) {
> >             if (broker.isInTransaction()) {
> >                 broker.abortTransaction();
> >             }
> >
> >             m_log.error("Selection could not be saved ! Transaction is
> > rolled back.", pbe);
> >         } finally {
> >             if (broker != null) {
> >                 file://broker.close();
> >             }
> >         }
> >         return ok;
> >
> >     } file://end
> >
> > I have debugged the code and the problem is broker.store(sel)
> > I'm currently using the DefaultSequenceMangerImpl which stores the MAX
> ID's
> > for each table in Object SequenceEntry, within the store-process a new
> > Identity is created for SequenceEntry with the construtor of Identity
> (only
> > the last lines ...)
> >             else
> >             {
> >                 broker =
> > PersistenceBrokerFactory.defaultPersistenceBroker();
> >                 ClassDescriptor cld =
> > broker.getClassDescriptor(objectToIdentitify.getClass());
> >
> >                 // identities must be unique accross extents !
> >                 this.objectsClass =
> > broker.getExtentClass(objectToIdentitify.getClass());
> >                 this.objectsRealClass = objectToIdentitify.getClass();
> >                 this.pkValues = cld.getKeyValues(objectToIdentitify);
> >             }
> >
> >             checkForPrimaryKeys();
> > <<<< passed and jump to finally >>>>
> >         }
> >         catch (Throwable t)
> >         {
> >             LoggerFactory.getDefaultLogger().error(t);
> >             throw new
> ClassNotPersistenceCapableException(t.getMessage(),
> > t);
> >         }
> >         finally
> >         {
> >         if (broker != null)
> >         {
> >             broker.close();
> >         }
> >         }
> >
> > The last statement is broker.close() which is the problem. It releases
> the
> > connection and the connectionManager used by the broker gets in state
> > inLocalTransaction = false that on the other Hand raises the exception
> > within ConnectionManager.localCommit()
> > <<<
> >     public void localCommit()
> >     {
> > //        if (log.isDebugEnabled()) log.debug("commit was called");
> >         if (!this.isInLocalTransaction)
> >         {
> >             throw new TransactionNotInProgressException("Not in
> transaction,
> > call begin() before commit()");
> >         }
> > ...
> > >>>>>
> >
> > There's the problem. Hmm, I'm a little bit confused. The code says
> that
> > should happen every time i wanna use transactions with the PB API. In
> the
> > case a Identity is constructed with constructor Identity(Object) and
> not the
> > one getting a broker as second argument.
> >
> > Is this a bug ? Related to the SequenceManager ? I think it is not
> related
> > to ODMG or PB API, isn't ?
> >
> > Thanx for your help.
> > Thomas
> >
> > > -----Ursprungliche Nachricht-----
> > > Von: Thomas Mahler [mailto:[EMAIL PROTECTED]]
> > > Gesendet: Dienstag, 3. September 2002 20:50
> > > An: OJB Users List
> > > Betreff: Re: TransactionNotInProgressException and AutoCommit
> Question
> > >
> > >
> > > Your stacktrace indicates that you have mixed PersistenceBroker and
> ODMG
> > > Transactions !
> > >
> > > The code you present here does IMHO not match to the stacktrace
> where we
> > > see a org.apache.ojb.odmg.TransactionImpl.abort() first.
> > > Your code snippet does not contain such a call???
> > >
> > > cheers,
> > > Thomas
> > >
> > >
> > > Thomas Fahrmeyer wrote:
> > > > Hi,
> > > >
> > > > If I try to save a new object I get the exeption
> > > >
> > > > ----- Root Cause -----
> > > > org.apache.ojb.broker.TransactionNotInProgressException
> > > > at
> > > >
> > > org.apache.ojb.broker.singlevm.PersistenceBrokerImpl.abortTransact
> > > ion(Persis
> > > > tenceBrokerImpl.java:266)
> > > > at
> > > org.apache.ojb.odmg.TransactionImpl.abort(TransactionImpl.java:505)
> > > > at
> > > >
> > > de.virtualsolution.struts.actions.UpdateSelectionAction.updateSele
> > > ctionODMG(
> > > > UpdateSelectionAction.java:225)
> > > >
> > > > that happend with the following code:
> > > >
> > > >
> > > >>>>>snippet
> > > >>>>
> > > >            broker.beginTransaction();
> > > >
> > > >            // a new object
> > > > broker.store(sel);
> > > >
> > > >             // 7. commit transaction
> > > >             broker.commitTransaction();
> > > >         } catch (PersistenceBrokerException pbe) {
> > > >             if (broker.isInTransaction()) {
> > > >                 broker.abortTransaction();
> > > >             }
> > > >
> > > >             m_log.error("Selection could not be saved !
> Transaction is
> > > > rolled back.", pbe);
> > > >         } finally {
> > > >             if (broker != null) {
> > > >                 broker.close();
> > > >             }
> > > >         }
> > > > <<<<< end
> > > >
> > > > the call to commitTransaction() raises this exception.
> > > >
> > > > The object is saved correctly anyway. Is that related to the
> autoCommit
> > > > Settings in OJB.properties ? Which settings should I use if I
> wanna use
> > > > begin- and commitTransaction() any time ?
> > > > I have tried to set the autoCommit-level to 2 in OJB.properties
> and even
> > > > ignoreAutoCommitException to true, but doesn't change anything.
> > > >
> > > > Can someone help me out (i'm convinced ;)
> > > >
> > > > bye
> > > > Thomas
> > > >
> > > >
> > > > --
> > > > 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]>
> >
> >
> > --
> > 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]>
>


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

Reply via email to