This one time, at band camp, Jan Ploski said:

JP>I have my database schema arranged as follows:
JP>
JP>Table "model", PK = id
JP>Table "traffic_node", PK = (modelID, id)
JP>
JP>traffic_node.modelID refers to model.id.
JP>traffic_node.id is NOT alone unique in the table traffic_node.
JP>
JP>I would like to create a mapping for traffic_node and I don't know
JP>what to put as the "identity" attribute and how to specify field mappings.
JP>On the Java side, I do NOT (!) need a reference to Model in a TrafficNode.
JP>As a matter of fact, the read-only attribute "modelID" is not supposed
JP>to be stored in any way in TrafficNode instances. It is used in SELECTs,
JP>though, to obtain all TrafficNodes that belong to a certain Model.
JP>
JP>Why do I need such an apparently strange arrangement? It is due to
JP>a design decision that enables easy deep copying of Models on the
JP>SQL level. For example, to clone model with oldModelID, I would execute:
JP>
JP>INSERT INTO model (id, ...)
JP>    SELECT generateNewID(), .. FROM model WHERE id=oldModelID;
JP>
JP>newModelID = generatedNewID();
JP>
JP>INSERT INTO traffic_node (modelID, id, ...)
JP>    SELECT newModelID, id, ... FROM traffic_node WHERE modelID=oldModelID;
JP>
JP>INSERT INTO road (modelID, id, ...)
JP>    SELECT newModelID, id, ... FROM road WHERE modelID=oldModelID;
JP>
JP>This third INSERT statement is tricky because each road refers
JP>to two traffic_nodes. I am taking advantage of the fact that the ids
JP>of cloned traffic_nodes remain unchanged, the only part that differs
JP>is the modelID. So the referential integrity of the cloned model is
JP>guaranteed. Without that arrangement, I would need to somehow associate
JP>each cloned road with the new IDs of respective two cloned traffic_nodes.
JP>That seems to translate into executing 10,000 SQL statements (one for
JP>each road in the model) instead of just a few.
JP>
JP>I found an old message on this list stating that foreign keys
JP>being part of primary keys are "not supported in Castor". To what
JP>extent does it apply? Is it possible to create a mapping.xml that
JP>would handle my scenario? I'd love to be able to execute a query like
JP>
JP>select n from simflo.model.TrafficNode n where modelID=$1

Jan, 

Unfortunately, this is still a bug with Castor
(http://bugzilla.exolab.org/show_bug.cgi?id=925).

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

Reply via email to