Monday, May 5, 2008

EOGlobalIDs for Abstract Entities

I just got burned by this and it was a bitch to figure out. I had an ERXBatchingDisplayGroup that was fetching an abstract entity type that used Single Table Inheritance. It turns out that the way ERXBDG was fetching, it fetched the page of PK's, turned those into faults, then fired the faults. The problem with this is that if you turn a PK into a fault for an abstract entity type (note that it just has the PK, so it doesn't know the actual subentity yet), EOF decides to fetch the object so it can resolve the entity name for the global id. You'll see this as a bunch of one-by-one fetches in your log. Needless to say this is total crap.

It turns out that you can instead turn each PK into a GID directly with entity.globalIDForRow(pkDict). Inside of EOGlobalID, it already tracks the concept of not knowing the final subclass type. When you attempt to turn this global ID into an EO (using ERXGlobalIDUtilities, or whatever), EOF will properly fetch the objects and everyone will be happy. The nice thing here is that ERXGIDUtils can batch those fetches into a single query so you don't get 40, 50, 100 (or whatever your page size is) hits to the DB. This SEEMS like a bug in EOF to me, though I won't say that this won't totally burn me at some point. (by "me," I mean "all of us" since this has now been changed in ERXBatchingDisplayGroup).