2009/10/2 Robert Krüger <[email protected]>:
> Person {
> Association<Company> company();
> }
>
> Company {
> ManyAssociation<Person> employees();
> ManyAssociation<Person> owners();
> }
>
> Qi4j cannot know anything about the semantics so it has no way of knowing if
> company is the inverse of employees or owners. Is there a way to specify
> this via an annotation?
1. Correct, Qi4j will not know (and we have not found any reason for
it to know it either) any 'directional' information in associations.
If you can give us some usecases when this information is needed,
perhaps we can evaluate its relevance.
2. In general, try to avoid bi-directional associations. It simplifies
a lot. For instance, in your model you put in a association to
"company" for a Person (which should be Employee), but perhaps the
Person works for multiple Companies at the same time.
3. Qi4j has the notion of Aggregated, so if for instance the
'association owner' is deleted, then the associated entities are also
deleted. Aggregated is built-in with that semantics, but we expect
more semantics to follow in later versions, possibly supporting
"Aggregate Roots" and "Aggregate Locks & Isolation".
If we elaborate on your example a little bit. Employees are really its
own Entity (actually, I would try to make it a Value composite
instead), since there will be additional properties associated with
the employment and not the Person. And assuming Company is a
shareholding company, we will have Shareholding as another Entity, and
those shares can be held by either Company or Person, a.k.a
LegalEntity...
Person extends LegalEntity;
Employee {
Association<Company> company();
Association<Person> person();
Property<Date> startedDate();
}
Shareholding {
Association<LegalEntity> owner();
Property<Long> shares();
}
Company extends LegalEntity {
@Aggregated
ManyAssociation<Employee> employees();
@Aggregated
ManyAssociation<Shareholding> owners();
}
If the Company is deleted (can not actually happen in the real world)
the shareholdings and employees will be deleted with it, but the
associations in Employee and Shareholding are not propagated to its
associations.
Makes sense?
Cheers
--
Niclas Hedhman, Software Developer
http://www.qi4j.org - New Energy for Java
I live here; http://tinyurl.com/2qq9er
I work here; http://tinyurl.com/2ymelc
I relax here; http://tinyurl.com/2cgsug
_______________________________________________
qi4j-dev mailing list
[email protected]
http://lists.ops4j.org/mailman/listinfo/qi4j-dev