This one time, at band camp, Enrico Thor said:
ET>> Are you using a key-generator? If so, I'm guessing that your
ET>> problem is probably due to the fact that the key generator is
ET>> not run before the object is persisted, hence the object id of zero.
ET>>
ET>> Bruce
ET>> --
ET>> perl -e 'print
ET>> unpack("u30","<0G)U8V4\@4VYY9&5R\"F9E<G)E=\$\!F<FEI+F-O;0\`\`");'
ET>
ET>thanks, you are right: the zero-problem is solved when resigning
ET>key-generator.
ET>
ET>But: Is this the expected behavior of the key-generator? In the
ET>castor-doc's it says "during >create< the value of the identity field is
ET>set to the value obtained from the key generator". So if I call
ET>"create(B)" before "create(A)" (in A.jdoBeforeCreate) the sequence value
ET>must have already been fetched.
ET>
ET>I see two possible reasons for the problem:
ET>
ET>1. Since the foreign-key-constraint is still violated I suppose that
ET>"jdoBeforeCreate()" is actually called after calling create() on the 'A'
ET>object. (This version is actually backed by the output of the logger
ET>(create(A) appears before create(B))).
ET>
ET>2. The behavior of the key-generator is not corresponding to the
ET>documentation (above). (But this would not explain the
ET>foreign-key-constraint-problem.)
ET>
ET>So in any case - at least any I can see right now - there must be an
ET>error.
ET>
ET>Assuming that the error is the wrong order of calling
ET>"jdoBeforeCreate()" in castor one workaround I can see for this problem
ET>is:
ET>
ET>* drop foreign-key-constraint,
ET>* resign key-generation for depending entity (B in example above) and
ET>* fetch the sequence value for depending entity manually and set it
ET>before calling create(B).
ET>
ET>The trouble I have with this workaround is that I forgo using database
ET>integrity mechanisms, so I will probably end up working arround
ET>persistence framework by directly calling create(B), A.setB(B),
ET>create(A).
Enrico,
Based on this thread, that seems fine. But, then again, I haven't seen your
object model or your mapping. Try it out and see what happens.
Bruce
--
perl -e 'print unpack("u30","<0G)U8V4\@4VYY9&5R\"F9E<G)E=\$\!F<FEI+F-O;0\`\`");'
-----------------------------------------------------------
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
unsubscribe castor-dev