I find your pattern very 'odd', and I am too tired right now to even try to understand how you came to this modeling decision.

If you want to limit the number of available instances, you should simply prohibit it, either via a Constraint or by throwing an Exception in lifecycle methods. Modifying Identity is not the way to go, IMNSHO.


Okay, let's reverse the setting of a problem.

I have a role X with property y. I need X.y() to be unique in scope of entity type. That means, from all entites of type Z, that have role X, if there is some entity that has V as value of X.y(), there are no other entites of type Z, that have same V as value of X.y(). How do I achieve that?

One way to do this by creating life-cycle mixin, which in create() queries all the entities of current type, having their X.y() as the value of X.y() of current entity. If query returns any results, it throws lifecycle-exception. This requires adding a querying service to your app.

Another way is described in QI-272. Is that too hacky?

Are there any other ways?


_______________________________________________
qi4j-dev mailing list
[email protected]
http://lists.ops4j.org/mailman/listinfo/qi4j-dev

Reply via email to