Re: xdoclet foreign key requirements
On Mon, 10 May 2004, Mike Traum wrote: > 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? >From what I see in your example, you're putting all @ojb tags into the class javadoc comment. This is not the intended place (at least for OJB) if there are actual fields of that name in the class (and I probably should add a warning into the module). When you put ojb.field and ojb.reference tags into the class javadoc comment, you're effectively generating anonymous fields and anonymous references. The former probably work for you, but the latter are only allowed for super-references used for mapping inheritance hierarchies manually. I'd suggest that if the fields are actually present in your class, then put the ojb.field tags into their javadoc tags (you then do not need to declare the name nor, in most cases, the jdbc-type). > 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. Right, and that's why you need a collection rather than a reference (which is only for 1:1). For collection tags you however need an actual collection in the class. As it seems that you're trying to model the super-subclass relationship with this collection, it depends on your usage of the table whether you really need the collection anyway. If you have all columns of the superclass table duplicated in the subclass table (as the OJB XDoclet module generates), then you probably do not need the explicit relationship because no join is necessary between the superclass table and the subclass table. Tom - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: xdoclet foreign key requirements
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 refe
Re: xdoclet foreign key requirements
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). > 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. Tom - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
xdoclet foreign key requirements
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 2. The number of foreign keys needs to be the same as the number of primary keys Is there any way around these restrictions? thanks, mike