Inverses - possible new feature for comment
Posted: Fri Aug 07, 2009 11:17 am
by Craig Shearer >> Tue, 21 Dec 1999 1:10:49 GMT
Hello all
I've been thinking... (some may say that's a dangerous thing to do)
One thing that often gets in the way with inverses is that they work all the time. Consider the following real life example from one of our systems:
Class InsuranceProductQuestion
collection property: allMyAnswersToQuestions - type AnswerToQuestionSet
Class AnswerToQuestion
property: myQuestion - type InsuranceProductQuestion
There is an inverse between these two classes in that setting the myQuestion reference on an AnswerToQuestion object causes the allMyAnswersToQuestions collection to be populated.
This all works fine and dandy except that in our application, we often have transient instances of AnswerToQuestion objects. These are used by the application for storing changes made to objects. When the user clicks a finish button in a wizard, these changes are then copied back to the persistent objects. However, this causes problems when the myQuestion reference is set:
Because the AnswerToQuestion object is transient, setting the myQuestion reference to the persistent InsuranceProductQuestion object causes an exception (1215) "Persistent Objects cannot reference Transient Objects". This is a real pain. I have numerous other examples where this has occurred, and we have needed to find less-than-ideal workaround solutions.
For us, the workaround is to add another reference to the AnswerToQuestion class - myPersistentQuestion which has the inverse back to the InsuranceProductQuestion class. For persistents, both the myQuestion and myPersistentQuestion references are set, but for transients, only the myQuestion reference can be set. While this works, it has the following disadvantages:
- it corrupts the purity of the model
- one must be careful that only the myQuestion reference is used, and not the myPersistentQuestion reference as this may be null.
- the second reference is difficult to name, as it exists only for implementation reasons
I would like to suggest a new feature - how about, when defining an inverse, having a facility for saying when the inverse will be maintained:
1. Always maintain inverse
2. Only between objects with compatible lifetimes
The second option would mean that inverses would only be maintained between persistents or transients, but not between mixed object lifetimes.
What do you think of this idea?
Craig.
Hello all
I've been thinking... (some may say that's a dangerous thing to do)
One thing that often gets in the way with inverses is that they work all the time. Consider the following real life example from one of our systems:
Class InsuranceProductQuestion
collection property: allMyAnswersToQuestions - type AnswerToQuestionSet
Class AnswerToQuestion
property: myQuestion - type InsuranceProductQuestion
There is an inverse between these two classes in that setting the myQuestion reference on an AnswerToQuestion object causes the allMyAnswersToQuestions collection to be populated.
This all works fine and dandy except that in our application, we often have transient instances of AnswerToQuestion objects. These are used by the application for storing changes made to objects. When the user clicks a finish button in a wizard, these changes are then copied back to the persistent objects. However, this causes problems when the myQuestion reference is set:
Because the AnswerToQuestion object is transient, setting the myQuestion reference to the persistent InsuranceProductQuestion object causes an exception (1215) "Persistent Objects cannot reference Transient Objects". This is a real pain. I have numerous other examples where this has occurred, and we have needed to find less-than-ideal workaround solutions.
For us, the workaround is to add another reference to the AnswerToQuestion class - myPersistentQuestion which has the inverse back to the InsuranceProductQuestion class. For persistents, both the myQuestion and myPersistentQuestion references are set, but for transients, only the myQuestion reference can be set. While this works, it has the following disadvantages:
- it corrupts the purity of the model
- one must be careful that only the myQuestion reference is used, and not the myPersistentQuestion reference as this may be null.
- the second reference is difficult to name, as it exists only for implementation reasons
I would like to suggest a new feature - how about, when defining an inverse, having a facility for saying when the inverse will be maintained:
1. Always maintain inverse
2. Only between objects with compatible lifetimes
The second option would mean that inverses would only be maintained between persistents or transients, but not between mixed object lifetimes.
What do you think of this idea?
Craig.