Here's my example:
-------------------------- BEGIN PARENT TABLE --------------------------
/**
* @ojb.class table="USERPREFDEF"
* documentation="User Preference Definitions and User
Preference Valid Value tables, which
* allow specific preference options to be defined and a list of
valid values added for them. User
* Preferences are similar to Setup values, but instead of being
specific only to an application they
* are specific to a single user. "
*
* @ojb.field name="ClassName"
* documentation="The owning class. Usually set the class
name to this.getClass().getName()
* when querying the user preferences"
* jdbc-type="VARCHAR"
* length="128"
* primarykey="true"
* @ojb.field name="PrefCode"
* documentation="The other part of the primary key. ex:
countries"
* jdbc-type="VARCHAR"
* length="30"
* primarykey="true"
* @ojb.field name="Descrip"
* documentation="The friendly name of the user preference
that will appear on the auto-generated
* forms."
* jdbc-type="CHAR"
* length="132"
* @ojb.field name="DefaultVal"
* documentation="The default value for the user preference"
* jdbc-type="VARCHAR"
* length="80"
*
*
*/
public class UserPreferenceDef
extends SecurityDBObject
-------------------------- END PARENT TABLE --------------------------
-------------------------- BEGIN CHILD TABLE --------------------------
/**
* @ojb.class table="USERPREF"
* documentation="User Preferences"
* include-inherited="false"
*
* @ojb.field name="ExpUid"
* documentation="The integer user id. Primary Key Part 1"
* jdbc-type="INTEGER"
* primarykey="true"
* @ojb.field name="ClassName"
* documentation="The owner class name. Primary Key Part 2"
* jdbc-type="VARCHAR"
* length="128"
* primarykey="true"
* @ojb.field name="PrefCode"
* documentation="The preference code. Part3 of the primary
key."
* jdbc-type="VARCHAR"
* length="30"
* primarykey="true"
* @ojb.field name="PrefValue"
* documentation="The actual value for this user."
* jdbc-type="VARCHAR"
* length="80"
*
* @ojb.reference name="super"
*
class-ref="com.jcorporate.expresso.services.dbobj.UserPreferenceDef"
* foreignkey="ClassName,PrefCode"
*
*/
public class UserPreference
extends SecurityDBObject
-------------------------- END CHILD TABLE --------------------------
On Mon, 2004-05-10 at 14:36, Thomas Dudziak wrote:
> On Mon, 10 May 2004, Mike Traum wrote:
>
> > I am attempting to use the @ojb tags and xdoclet to generate a torque
> > schema for a project which isn't using ojb. I've found that they have
> > these 2 requirements regarding foreign keys:
> > 1. The table containing foreign keys needs to be a subclass of the
> > primary key table
>
> I don't think I understand what you are saying here. Could you perhaps
> provide an example to illustrate this ?
> Also please be aware that there two different situations where foreign
> keys are used: references (1:1) and collections (1:n, m:n). In the former,
> the foreign key field(column) is defined in the class(table) that owns the
> reference. In the latter case, the foreign key is defined in the
> referenced object (inverse foreign key).
>
The above example doesn't work because of the @ojb.reference requirement
that the child table must be a child class of the parent table's class.
I've tried to manually override this using @ojb.extent-class, but it
also has the same requirement. This is probably a necessity of ojb, but
I'm not using ojb and would like to get around this requirement. Is
there any way?
> > 2. The number of foreign keys needs to be the same as the number of
> > primary keys
>
> No, because the reference from the owning to the owned object is
> established with these pairs. If you have less foreign keys than primary
> keys, then you possibly end up referencing more than one object (because
> one part of the 'key' is undefined). If you have more foreign keys than
> primary keys, then several foreign key fields have values without
> meaning. and without explicitly defining which foreign key maps to which
> primary key, it is unclear which foreign key values have meaning and which
> not. In OJB, this btw is established with the position in the class
> (primary key) and reference/collection (foreign key) declarations.
If I change UserPreference to extend UserPreferenceDef (so that I can
get by the above issue), I get the error:
[ojbdoclet] xdoclet.XDocletException: The number of foreignkeys (2) of
the reference super doesn't match the number of primarykeys (3) of the
referenced class (or its subclass)
com.jcorporate.expresso.services.dbobj.UserPreference
I have three primary keys in the child and two in the parent, but it's
still a one-to-many relationship.
thanks,
mike
>
> Tom
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]