Persistence: loading whole object before adding it [message #712577] |
Sun, 07 August 2011 08:58  |
Eclipse User |
|
|
|
Hi,
I have a problem with persistence of my EMF model. I save my model as XMI. Sometimes I have an object (say A) which has to be complete (all of its features loaded from the file) before it is set as a value of some reference from object B. I have discovered that the parser sets A as value right after reading all attributes of its defining element. The parser, however, resolves nested elements of A (representing references) AFTER A is set as value.
I have an adapter attached to object B which presumes that A has all its references non-NULL before it is attached to B.
Is there some way to ensure that object A is loaded with all of its features resolved before its is added as a value to B?
Thanks in advance
|
|
|
|
|
|
Re: Persistence: loading whole object before adding it [message #712643 is a reply to message #712627] |
Sun, 07 August 2011 10:40  |
Eclipse User |
|
|
|
Martin,
Comments below.
On 07/08/2011 7:20 AM, Martin odlouck wrote:
> Thank your for quick response. I see what are you traying to tell me.
> My model is rather specific so I try to create simplier example. Let's
> suppose object A is a student and B is a students club. Every student
> has a reference to the university he/she attands. When calling
> club.getStudents().add(student), the club needs to check
> student.getUniversity().getName() to assign him responsibilities (for
> example).
I would have imagined the assignment of responsibilities are themselves
serialized and are set appropriately based on that persisted information.
> If student's university is NULL the club does not know what to do with
> him.
Suppose he was expelled? How should the model update? Suppose he
transfers to a different university. Should he be removed from the club
too?
> So what si the best solution in such a case? The clubs accesses the
> student's reference to university immediately after addition.
If you serialize universities before students in a single resource (it's
bad news to resolve proxies to university during loading if they are in
a different resource) and serialize the student's reference to the
university before that of their references to clubs, that will help;
these can be controlled with the order at the root of the resource of
the feature order in the classes.
> However, the university reference is loaded later.
Is that because of feature order in the class?
Without all the details of what are containment references, how many
resources are involved, and so on, it's very hard to give specific
answers. One thing is for sure though, these order dependencies of what
must be set first are problematic from all aspects. Even when working
with the API, it will be necessary to assign the university before
assigning club; who's to know that just looking at the API...
|
|
|
Powered by
FUDForum. Page generated in 0.04130 seconds