Hi Jakob,
Yes, your patch did the trick! No more selects with id = null. Thanks!
Gerhard
Jakob Braeuchi <[EMAIL PROTECTED]>
15.10.2003 17:56
An: [EMAIL PROTECTED]
Kopie:
Thema: [Fwd: Re: Antwort: RE: How to map optional 1:1 relationship]
----- Nachricht von Jakob Braeuchi <[EMAIL PROTECTED]> auf Wed, 15 Oct 2003
17:49:54 +0200 -----
An:
OJB Users List <[EMAIL PROTECTED]>
Thema:
Re: Antwort: RE: How to map optional 1:1 relationship
hi gerhard,
sorry, i posted to wrong code. this is it:
protected void associateBatched(Collection owners, Collection
children)
{
ObjectReferenceDescriptor ord = getObjectReferenceDescriptor();
ClassDescriptor cld = getOwnerClassDescriptor();
Object owner, relatedObject;
Object fkValues[];
Identity id;
PersistenceBroker pb = getBroker();
PersistentField field = ord.getPersistentField();
Class topLevelClass = pb.getTopLevelClass(ord.getItemClass());
Iterator iter = owners.iterator();
while (iter.hasNext())
{
owner = iter.next();
fkValues = ord.getForeignKeyValues(owner,cld);
if (!isNull(fkValues))
{
id = new Identity(null, topLevelClass, fkValues);
relatedObject = pb.getObjectByIdentity(id);
}
else
{
relatedObject = null;
}
field.set(owner, relatedObject);
}
}
jakob
[EMAIL PROTECTED] wrote:
> hi again,
>
> I think this is indeed the reason. In my log files those selects almost
> always occur right after prefetch queries. And in the few cases they
> don't, it may just be that there was no non-null FK to prefetch.
>
> Method ReferencePrefetcher#buildPrefetchQueries already checks for
isNull(fkValues) so
> #associateBatched should probably do the same.
>
> Gerhard
>
>
>
>
>
> Jakob Braeuchi <[EMAIL PROTECTED]>
> 15.10.2003 17:17
> Bitte antworten an "OJB Users List"
>
>
> An: OJB Users List <[EMAIL PROTECTED]>
> Kopie:
> Thema: Re: Antwort: RE: How to map optional 1:1 relationship
>
>
> hi carl,gerhard,
>
> your right, fkValues may be null and thus a query will be fired.
> can you confirm this gerhard ?
>
> jakob
>
> Boyes, Carl wrote:
>
>
>>Hi Jakob, Gerhard
>>
>>In ReferencePrefetcher#associateBatched:
>>
>>...
>> while (iter.hasNext())
>> {
>> owner = iter.next();
>> fkValues = ord.getForeignKeyValues(owner,cld);
>> id = new Identity(null, topLevelClass, fkValues);
>> relatedObject = pb.getObjectByIdentity(id);
>> field.set(owner, relatedObject);
>> }
>>...
>>
>>Should this also be ensuring a non null foreign key value?
>>
>>Carl.
>>
>>
>>
>>-----Original Message-----
>>From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
>>Sent: Wednesday, October 15, 2003 3:59 PM
>>To: OJB Users List
>>Subject: Re: Antwort: RE: How to map optional 1:1 relationship
>>
>>
>>Hi Jakob,
>>
>>I just checked and you are right.
>>
>>Nevertheless I find a lot of statements like SELECT ... FROM ... WHERE
>>id='' in my P6Spy logs, where id is a not nullable primary key. I was
>>assuming these were generated from resolving references with FK=null,
>
> but
>
>>it turns out this is wrong. Looks like I'll have to do a little more
>>research to find the reason for these selects...
>>
>>Regards,
>>Gerhard
>>
>>
>>
>>
>>
>>Jakob Braeuchi <[EMAIL PROTECTED]>
>>15.10.2003 16:10
>>Bitte antworten an "OJB Users List"
>>
>>
>> An: OJB Users List <[EMAIL PROTECTED]>
>> Kopie:
>> Thema: Re: Antwort: RE: How to map optional 1:1 relationship
>>
>>
>>hi gerhard,
>>
>>imo this is already implemented. see
>>PersistenceBrokerImpl#getReferencedObject:
>>
>>...
>> // BRJ: check if we have non null pk values
>> // TBD we should also check primitives
>> // to avoid creation of unmaterializable proxies
>> for (int i = 0; i < pkVals.length; i++)
>> {
>> if (pkVals[i] != null)
>> {
>> allPkNull = false;
>> break;
>> }
>> }
>> // BRJ: if all pk values are null there's no referenced object
>> if (allPkNull)
>> {
>> return null;
>> }
>>...
>>
>>
>>The contents of this email are confidential to the intended recipient at
>
> the email address to which it has been addressed. It may not be
disclosed
> to or used by anyone other than this addressee, nor may it be copied in
> any way. If received in error, please contact DLA, a UK law firm,
> (http://www.dla.com/) on +44 (0) 8700 111111 quoting the name of the sender and the
> addressee
> and then delete it from your system.
>
>>Please note that neither DLA nor the sender accepts any responsibility
>
> for viruses and it is your responsibility to scan the email and
> attachments (if any). No contracts may be concluded on behalf of DLA by
> means of email communications.
>
>>A list of the names of the partners of DLA (who are either solicitors or
>
> registered foreign lawyers) and their qualifications is available for
> inspection at 3 Noble Street, London, EC2V 7EE, UK.
>
>>Regulated by the Law Society.
>>
>>
>>
>>---------------------------------------------------------------------
>>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]
>
>
>
>