Hi,

After several days trying to use Multiple Joined Tables with XDoclet, I can do this work, but there are more things with Multiple Joined Table and XDoclet that I need to know how to do.

first this are sample classes for better understanding:

/**
* @ojb.class table="PERSON"
* determine-extents="false"
**/
public class Person {
/**
* @ojb.field column="OID"
* length="8"
* primarykey="true"
**/
public String oid;
/**
* @ojb.field column="VERSION"
* locking="true"
**/
public int version;


   /**
   * @ojb.field column="SHORTCUT"
   *            length="20"
   **/
   String shortcut;

   /**
   * @ojb.field column="NAME"
   *            length="40"
   **/
   String name;

   /**
   * @ojb.collection element-class-ref="Address"
   *                 foreignkey="myPersonOid"
   *                 auto-retrieve="true"
   *                 auto-update="object"
   *                 auto-delete="object"
   **/
   java.util.Vector myAddress;
}

/**
* @ojb.class table="COMPANY"
*            include-inherited="false"
* @ojb.field name="oid"
*            column="oid"
*            jdbc-type="VARCHAR"
*            length="8"
*            primarykey="true"
* @ojb.reference class-ref="Person"
*                foreignkey="oid"
*                auto-retrieve="true"
*                auto-update="object"
*                auto-delete="object"
**/
public class Company extends Person {

/**
* @ojb.field column="FOUNDATION_DATE"
* conversion="org.apache.ojb.broker.accesslayer.conversions.JavaDate2SqlTimestampFieldConversion"
* jdbc-type="TIMESTAMP"
**/
java.util.Date foundationDate;
}



/** * @ojb.class table="NATURALPERSON" * include-inherited="false" * @ojb.field name="oid" * column="oid" * jdbc-type="VARCHAR" * length="8" * primarykey="true" * @ojb.reference class-ref="Person" * foreignkey="oid" * auto-retrieve="true" * auto-update="object" * auto-delete="object" **/ public class NaturalPerson extends Person { /** * @ojb.field column="MOTHER_NAME" * length="40" **/ String motherName;

   /**
   * @ojb.field column="FATHER_NAME"
   *            length="40"
   **/
   String fatherName;
}

/**
* @ojb.class table="ADDRESS"
* @ojb.field name="myPersonOid"
*            column="MY_PERSON"
*            jdbc-type="VARCHAR"
*            length="8"
* @ojb.field name="myCityOid"
*            column="MY_CITY"
*            jdbc-type="VARCHAR"
*            length="8"
**/
public class Address {

   /**
   * @ojb.field column="OID"
   *            length="8"
   *            primarykey="true"
   **/
   public String oid;

   /**
   * @ojb.field column="VERSION"
   *            locking="true"
   **/
   public int version;

/**
* @ojb.field column="STREET"
* length="40"
**/
String street;
/**
* @ojb.reference foreignkey="myCityOid"
**/
City myCity;
}


/**
* @ojb.class table="CITY"
**/
public class City {
   /**
   * @ojb.field column="OID"
   *            length="8"
   *            primarykey="true"
   **/
   public String oid;

   /**
   * @ojb.field column="VERSION"
   *            locking="true"
   **/
   public int version;

   /**
   * @ojb.field column="NAME"
   *            length="40"
   **/
   String name;
}

/**
* @ojb.class table="USER"
* @ojb.field name="myCompanyOid"
*            column="MY_COMPANY"
*            jdbc-type="VARCHAR"
*            length="8"
* @ojb.field name="myNaturalPersonOid"
*            column="MY_NATURAL_PERSON"
*            jdbc-type="VARCHAR"
*            length="8"
**/
public class User {
   /**
   * @ojb.field column="OID"
   *            length="8"
   *            primarykey="true"
   **/
   public String oid;

   /**
   * @ojb.field column="VERSION"
   *            locking="true"
   **/
   public int version;

   /**
   * @ojb.field column="LOGIN"
   *            length="15"
   **/
   public String login;

   /**
   * @ojb.field column="PASSWORD"
   *            length="15"
   **/
   public String password;

   /**
   * @ojb.reference foreignkey="myCompanyOid"
   **/
   Person myCompany;

   /**
   * @ojb.reference foreignkey="myNaturalPersonOid"
   **/
   Person myNaturalPerson;
}

Issues:

1) For this works after repository_user.xml is generated, I manually remove the anonymous attribute of field oid from classes Company and NaturalPerson, then how do this, without override oid in subclasses? (If don't remove I get a java.lang.NullPointerException because oid is a primary key)

Now the querys that must work with this model. I don't use ODMG but I will explain in OQL because I use OQL to generate Criteria and appears to be more readable:

1) SELECT obj FROM User obj WHERE myCompany.myAddress.myCity.name = "CITY 1"

Works because the user reference points to a Person class.

2) SELECT obj FROM User obj WHERE myCompany.shortcut = "COMPANY 1" AND login = "USER 1"
Works like above.


3) SELECT obj FROM Company obj WHERE shortcut = "COMPANY 1"
Works OJB discover the shortcut field from Person and does a great job here.

3) SELECT obj FROM Company obj WHERE myAddress.myCity.name = "CITY 1"
Don't work, and throws a Database Exception Table must be in from list, because myAddress.myCity.name appears in SQL statement generated by OJB, here OJB does a bad job, because don't discover the collection of Address from Person. (I think that this can be done like for fields).
but in an email from Jakob he mentioned for me to redefine references in descriptor, doing that, works, but this redefination must be in repository_user.xml, how do it with XDoclet?


isn't better to OJB discover collections from super class like for fields?

TIA

Cl�vis


--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to