There is a way to do what you want.  You'd need to have 2 classes. A Vehicle
class and a Car class which extends Vehicle.

In the mapping file you'd also have two mappings one for Vehicle which
would have the super-class properties and a Car mapping which would
have the Car specific mappings.  The mapping would look like so:

  <class name="Vehicle" identity="id">
    <description>This is the car class</description>
    <map-to table="vehicle" />
    <field name="id" type="int">
      <sql name="id" type="integer"/>
    </field>
    <field name="color" type="string">
      <sql name="color" type="varchar"/>
    </field>
  </class>
  <class name="Car" extends="Vehicle">
    <description>This is the car class</description>
    <map-to table="car" />
    <field name="make" type="string">
      <sql name="make" type="varchar"/>
    </field>
    <field name="year" type="string">
      <sql name="year" type="varchar"/>
    </field>
  </class>

-- Don

-----Original Message-----
From: Chris Cook [mailto:[EMAIL PROTECTED]]
Sent: Monday, June 10, 2002 2:01 PM
To: [EMAIL PROTECTED]
Subject: [castor-dev] Beginner question


I'm trying to map a Java class into two database tables and was wondering if
that is supported using Castor.

For example I have a Car class in Java that looks like

public class Car{
        private int id;
        private String color;
        private String make;
        private String year;

        public String getColor(){...}
        public void setColor() {...}
        .
        .
        .
}

can that class map into the following database tables?
table vehicle (
  id   int not null,
  color varchar(200) not null
);

table car(
  id int not null, (foriegn key into vehicle)
  make varchar,
  year varchar
);

I know how it would look to one table, but not for two, for example
  <class name="Car" identity="id">
    <description>This is the car class</description>
    <map-to table="car" />
    <field name="id" type="int">
      <sql name="id" type="integer"/>
    </field>
    <field name="make" type="string">
      <sql name="make" type="varchar"/>
    </field>
    <field name="year" type="string">
      <sql name="year" type="varchar"/>
    </field>
  </class>

So to repeat the question, can the avove listed Car class map to both the
vehicle and car database tables

Thanks for your help,

Chris

-----------------------------------------------------------
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
        unsubscribe castor-dev

----------------------------------------------------------- 
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
        unsubscribe castor-dev

Reply via email to