• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: How to avoid expensive fetches in database when setting to-one-relationship
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to avoid expensive fetches in database when setting to-one-relationship


  • Subject: Re: How to avoid expensive fetches in database when setting to-one-relationship
  • From: Philippe Rabier <email@hidden>
  • Date: Mon, 06 Jun 2016 11:13:16 +0200

Hi Jeremy,

I highly doubt that all toMany relationships are fetched without something that triggers the fetch. 

You can read this article if you want to optimize the requests:
https://wiki.wocommunity.org/pages/viewpage.action?pageId=12943886

A rule of thumb is to remove the reverse relationships to any “parameters” entity like your transportMode entity. The only drawback is when you want to delete such an object because EOF can’t help you.

For that, you can take a look here: https://github.com/marchant/corason/blob/master/Frameworks/COFoundation/Sources/fr/sophiacom/corason/foundation/eo/COCheckDelete.java

How does it work? You add a key “checkDelete" in the EOEntity userInfo dictionary in your EOModel and True as value if you want to check that, for example, a transportMode object can be deleted or not.

Look at https://github.com/marchant/corason/blob/master/Frameworks/COFoundation/Sources/fr/sophiacom/corason/foundation/eo/COStampedEnterpriseObject.java as an example of implementation.

There is maybe (surely?) something in Wonder for that but as I did it before, I never checked.

Best,

Philippe

On 6 juin 2016, at 00:58, Jérémy DE ROYER <email@hidden> wrote:

In fact, I can understand that WebObjects fetches the orders of a customer when inserting a new order for this customer.

But I don’t understand why WebObjects fetches all the to many relationships of this customer ???? And how to tell WebObjects not to do it (;-)

Jérémy

Le 6 juin 2016 à 00:32, Chuck Hill <email@hidden> a écrit :

That is what I meant by fetching.  You need to re-implement those methods.   Change it to do an fetch on Customer where modeTransport == this
 
You can still use it to fetch a ModeTransport based on “listOrder contains order”. 
Chuck
 
 
From: Jérémy DE ROYER <email@hidden>
Date: Sunday, June 5, 2016 at 3:26 PM
To: Chuck Hill <email@hidden>
Cc: WebObjects-Dev <email@hidden>
Subject: Re: How to avoid expensive fetches in database when setting to-one-relationship
 
What do you mean with « you can still use it for fetching » ?
 
I removed the class property for the Customer to Order (but keeped the « listOrder » relationship)
 
When I set the customer to the order, it runs fast.
 
But when I retrieve the orders using the method below :
 
  public NSArray<Customer> listOrder() {
    return (NSArray<Customer>)storedValueForKey("listOrder");
  }
 
I get an error :
 
<com.webobjects.foundation.NSKeyValueCoding$UnknownKeyException message ‘<Customer 0x72c7423b> valueForKey(): lookup of unknown key: 'listOrder'.
This class does not have an instance variable of the name listOrder or _listOrder, nor a method of the name listOrder  _listOrder, getListOrder, or _getListOrder' object ‘{...}' key 'listOrder'>
at com.webobjects.foundation.NSKeyValueCoding$DefaultImplementation.handleQueryWithUnboundKey(NSKeyValueCoding.java:1377)
at com.webobjects.eocontrol.EOCustomObject.handleQueryWithUnboundKey(EOCustomObject.java:1545)
at com.webobjects.foundation.NSKeyValueCoding$Utility.handleQueryWithUnboundKey(NSKeyValueCoding.java:494)
at com.webobjects.foundation.NSKeyValueCoding$_KeyBinding.valueInObject(NSKeyValueCoding.java:894)
at com.webobjects.eocontrol.EOCustomObject.storedValueForKey(EOCustomObject.java:1634)
at Customer.listeOrder(_Customer.java:890)
 
Where am I wrong ?
 
Jérémy
 
Le 5 juin 2016 à 22:04, Chuck Hill <email@hidden> a écrit :
 
Remove the “class property” setting for the ModeTransport to Order.  You can still use it for fetching.
 
Chuck
 
 
From: <webobjects-dev-bounces+chill=email@hidden> on behalf of Jérémy DE ROYER <email@hidden>
Date: Sunday, June 5, 2016 at 12:55 PM
To: WebObjects-Dev <email@hidden>
Subject: How to avoid expensive fetches in database when setting to-one-relationship
 
Dear all, 
 
In our app, we have a one to many relationship between order and mode transport
 
For each order, we set the mode transport using the method below :
 
 
  public void setModeTransportRelationship(ModeTransport value) {
    if (_CommandeClient.LOG.isDebugEnabled()) {
      _CommandeClient.LOG.debug("updating modeTransport from " + modeTransport() + " to " + value);
    }
    if (value == null) {
    ModeTransport oldValue = modeTransport();
    if (oldValue != null) {
    removeObjectFromBothSidesOfRelationshipWithKey(oldValue, "modeTransport");
      }
    } else {
    addObjectToBothSidesOfRelationshipWithKey(value, "modeTransport");
    }
  }
 
 
Then, an objectWillChange() is fired for the mode transport… but the (not wished) consequence is that every to many relationships from the mode transport are fetched (even if we don’t call the associated method for the mode transport). However, the objects associated with the to one relationships are not fetched.
 
We observed the same behavior for the customer object when using the setCustomerRelationship method of the ordre. The (bigger) problem is that the customer object has dozen of to many relationships... fetched for nothing…
 
At the beginning we had few orders but now, we have to wait from 10 to 30 seconds until de saveChange is ended and that’s really not effective. More than 90 % of this time is spent for fetching the to many relationship whereas we just had to save the order values...
 
Any idea how to deal with theses not-wished-fetches ?
 
Jérémy
 

Do not post admin requests to the list. They will be ignored. Webobjects-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
References: 
 >How to avoid expensive fetches in database when setting to-one-relationship (From: Jérémy DE ROYER <email@hidden>)
 >Re: How to avoid expensive fetches in database when setting to-one-relationship (From: Chuck Hill <email@hidden>)
 >Re: How to avoid expensive fetches in database when setting to-one-relationship (From: Jérémy DE ROYER <email@hidden>)
 >Re: How to avoid expensive fetches in database when setting to-one-relationship (From: Chuck Hill <email@hidden>)
 >Re: How to avoid expensive fetches in database when setting to-one-relationship (From: Jérémy DE ROYER <email@hidden>)

  • Prev by Date: Re: How to avoid expensive fetches in database when setting to-one-relationship
  • Next by Date: Re: How to avoid expensive fetches in database when setting to-one-relationship
  • Previous by thread: Re: How to avoid expensive fetches in database when setting to-one-relationship
  • Next by thread: Question about jdbc connection pool
  • Index(es):
    • Date
    • Thread