This one time, at band camp, Jeszenszky Peter said:
JP>Consider a Foo class whose instances contain a vector of dependent Bar
JP>objects. The foo SQL table stores the Foo objects and the bar table the
JP>dependent Bar objects.
JP>
JP>Also consider a FooWithoutBars class that is mapped to the foo
JP>table and contains all fields of the Foo class except the vector of dependent
JP>objects.
JP>
JP>I would like to implement the Foo class using extension, it should extend the
JP>FooWithoutBars:
JP>
JP> public class Foo extends FooWithoutBars {
JP>
JP> Vector bars = new Vector();
JP>
JP> public void setBars(Vector _bars) {
JP> bar = _bars;
JP> }
JP>
JP> public Vector getBars() {
JP> return bars;
JP> }
JP> }
JP>
JP>How the corresponding <class> element should like in the mapping file?
JP>
JP>I have tried
JP>
JP> <class name="Foo" extends="FooWithoutBars">
JP>
JP> <cache-type type="none"/>
JP>
JP> <field name="bars" type="Bar" collection="vector">
JP> <sql many-key="foo_id"/>
JP> </field>
JP>
JP> </class>
JP>
JP>However that results in an exception (No mapping found for the class
JP>Foo). Why do I have to specify a <map-to> element if the class extends
JP>the base class just with a vector of dependent objects? Any idea how to
JP>workaround this problem?
Peter,
The exception you're seeing is a result of the ordering of the mapping
descriptor. In your case, FooWithoutBars needs to appear before Foo.
As for the need to specify the <map-to> element again, it's certainly
possible for one class to extend another but actually be persisted to a
different table, the requirement. That's the way I've always understood
it from the original authors anyway.
Bruce
--
perl -e 'print unpack("u30","<0G)[EMAIL PROTECTED]&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