Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF "Technology" (Ecore Tools, EMFatic, etc)  » [Teneo/EMF] Question
[Teneo/EMF] Question [message #615675] Tue, 11 March 2008 22:04
Jason Henriksen is currently offline Jason HenriksenFriend
Messages: 231
Registered: July 2009
Senior Member
Here's a really fun one for you guys. Sorry to post in both groups, but
I wanted to make sure both Ed and Martin see this.

I have an object that I've loaded from the database that has lists of
child object. These lists are lazily loaded.

So for example:

class Parent{
List<ChildA> aList;
List<ChildB> bList;

For efficiency, I've loaded aList but left bList uninitialized. I now
want to serialize this object to XML so I can send it in a SOAP message.
I ONLY want to send aList but not send bList. I didn't load that from
the DB so it shouldn't be a problem.

Except that eIsSet() on the list looks like this:

return (labNetworkMemberList != null &&

and calling labNetworkMemberList.isEmpty() causes the list to be loaded
from the database!!!
(And if I disconnect the session I get ObjectNotInitialized exceptions)

Once it's loaded the whole object gets serialized into the XML and the
benefit of lazy loading is lost.

It turns out that this is a really common problem using hibernate and
lazy loading with serialization. In fact, by using EMF we're ahead of
the game because we have the eIsSet() methods which we can hack. If we
apply this hack we can get the lazy loading behavior we want:

//... from inside of eIsSet ...
//--- this list may be initialized by Teneo/Hibernate or maybe not
// Note that we use reflection because only the server side has
// Teneo installed. Since these objects are used by the client
// and by the server we don't know if isInitialized() is present.
// On the client we ignore the exception and
// defer to the value set in isEmpty()
// On the server this fails out of the if check BEFORE isEmpty()
// gets called to prevent the list from being loaded.
boolean isInitialized=true;
try {
Class c = contactList.getClass();
Method m = c.getMethod("isInitialized", new Class[] {})
isInitialized = m.invoke(contactList, new Object[] {})
} catch (Exception e) {/* ignored exception */ }
return (labNetworkMemberList != null &&
isInitialized &&

I could write all the refection into a utility and then build a
refactoring tool that inserts a call to that utility into the middle of
the if statement for each list on the object, but I'm hoping you guys
have a better idea.

What we really have is a problem with the meaning of isEmpty(). EMF
assumes we mean to ask if the real list has no children. But in the
context of a serialization I wan to know if the current copy of the
object's list is empty.

So what do you guys think of all that? Am I better to refactor all the
generated code or should I be trying to augment isEmpty somehow? Or is
there some better way to handle this that I haven't found yet? Any
suggestions are much appreciated.


Jason Henriksen
Previous Topic:Loading a GMF diagram resource from Hibernate
Next Topic:Teneo: Problem with using QualifyingEntityNameStrategy
Goto Forum:

Current Time: Tue Aug 09 08:09:55 GMT 2022

Powered by FUDForum. Page generated in 0.01234 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top