Ian Hunter wrote:

So in short, only when calling store() on new objects can that work,
right?

yep!

So for now I'll need to have auto-update disabled for this to
work within my application framework.  Right ??


if you only want to set the FK in main object without load the referenced object - currently yes.


regards,
Armin



Regarding the validationQuery issue: rather than explain, since the code
is so small and simple, I'll just post it:

    static PersistenceBroker getBroker() {
        if (cleanCountdown > 0) {
            cleanCountdown--;
            if (cleanCountdown == 0) {
                org.apache.ojb.broker.metadata.MetadataManager mm =
org.apache.ojb.broker.metadata.MetadataManager.getInstance();
                org.apache.ojb.broker.metadata.ConnectionRepository cr =
mm.connectionRepository();
                org.apache.ojb.broker.PBKey k =
cr.getStandardPBKeyForJcdAlias ("default");
                org.apache.ojb.broker.metadata.JdbcConnectionDescriptor
jcd = cr.getDescriptor (k);
                org.apache.ojb.broker.metadata.ConnectionPoolDescriptor
cpd = jcd.getConnectionPoolDescriptor();
                cpd.setValidationQuery (null);
            }
        }
        return PersistenceBrokerFactory.defaultPersistenceBroker();
    }

     public static void dirtyMode() {
        cleanCountdown = MAX_VALIDATIONS;
        org.apache.ojb.broker.metadata.MetadataManager mm =
org.apache.ojb.broker.metadata.MetadataManager.getInstance();
        org.apache.ojb.broker.metadata.ConnectionRepository cr =
mm.connectionRepository();
        org.apache.ojb.broker.PBKey k = cr.getStandardPBKeyForJcdAlias
("default");
        org.apache.ojb.broker.metadata.JdbcConnectionDescriptor jcd =
cr.getDescriptor (k);
        org.apache.ojb.broker.metadata.ConnectionPoolDescriptor cpd =
jcd.getConnectionPoolDescriptor();
        cpd.setValidationQuery ("select 0");
    }

So everyone who wants a broker calls my static getBroker method that
wraps the actual PB API call, and any exception that I deem troublesome
enough calls dirtyMode() -- works like a champ so far.
-----Original Message-----
From: Armin Waibel [mailto:[EMAIL PROTECTED] Sent: Monday, June 07, 2004 9:20 PM
To: OJB Users List
Subject: Re: Question about OJB references and manually setting foreign
keys (Struts app)


Hi Ian,

 > originally turned on auto-update as well, until I realized that if I
 > just wanted to link the Customer to a new Account Manager, I would
 > actually have to load the corresponding User record from persistence
and
 > call "someCompany.setAccountManager (someUser)" or something to that
 > effect to get OJB to "see" the new foreign key, rather than just
 > setAccountManagerFK.

If you INSERT an object, it is possible only to link the FK values without the referenced objects available (since rc6). When OJB try to link the new object (set FK) but the referenced object was missed, the setting of FK values will be skipped.


> So here's my question: Is there a way to "override" auto-update such
> that I could force in a different foreign key or do I have to leave
> auto-update disabled? There are plenty of times where I would want
to
> handle auto-updates on a case by case basis, I think.
>
This feature (dynamically change of auto-xxx settings at runtime) will be introduced in version 1.1



> On another topic, I posted the other day about not wanting to have a > validationQuery running all the time -- I did manage to get my app to > detect a PersistenceBrokerException (other than foreign key violations) > and set a counter such that the system would subsequently use a > validationQuery for the next n number of calls, and then ditch the > validationQuery again for speed. That worked out great.

I'm interested in your solution. In OJB 1.1 we will introduce a pluggable ValidationStrategy interface which will allows the user to implement more sophisticated "validation queries".

regards,
Armin


Ian Hunter wrote:


I'm pretty new to OJB, so be gentle. I'm working on a Struts app,

using

the PB API, and I have a "Customer" object with an "Account Manager"
reference to a "User" object.


For instance, something like:

public Class User {
        public int getId();
        public String getName();
}

Public Class Company {
        public int getId();
        public String getName();
        public int getAccountManagerFK();
        public User getAccountManager();
}

For sake of convenience, I have a reference-descriptor within the
Company class-descriptor with auto-retrieve set to true.  I had
originally turned on auto-update as well, until I realized that if I
just wanted to link the Customer to a new Account Manager, I would
actually have to load the corresponding User record from persistence

and

call "someCompany.setAccountManager (someUser)" or something to that
effect to get OJB to "see" the new foreign key, rather than just
setAccountManagerFK.

So here's my question:  Is there a way to "override" auto-update such
that I could force in a different foreign key or do I have to leave
auto-update disabled?  There are plenty of times where I would want to
handle auto-updates on a case by case basis, I think.

Am I just looking at this wrong?


On another topic, I posted the other day about not wanting to have a validationQuery running all the time -- I did manage to get my app to detect a PersistenceBrokerException (other than foreign key

violations)

and set a counter such that the system would subsequently use a
validationQuery for the next n number of calls, and then ditch the
validationQuery again for speed.  That worked out great.




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





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

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




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



Reply via email to