Here's the correct mapping file ( ie: it works).
Notes on creating relations in Persistent storage:
one-to-many
A has many B. B is dependent on A
You have to have a method in B to add A to it. Like B.setA( A ). When
you add B to A like in A.addB( B ) the addB method in A has to call
B.setA( this ) to make the relation work. I had thought castor would do this
automatically but unfortunately it doesn't, though it's only one extra line
of code to add so is not a big problem. One to many relations aren't stored
in mapping tables but in the child objects.
many-to-many
C has 0 to many D, D can belong to 0 or many C.
You have to create D before adding it to C.
Like: db.begin() ;
D = new D();
db.create( D );
C.add( D );
db.create( C );
db.commit();
If you don't do this D and C will be created in storage but there won't
be any storage of the relationships in the mapping table.
This caused me a few headaches but was easy to fix. Thanks to Thomas for
pointing this out.
Hope it's what you wanted.
By the way it may help your chances of getting further help if you don't go
off in a tiff if someone points you to the right resources, but you can't
make head or tail of them. Not everything is always clearly explained.
Sometimes we just have to muddle our way through.(with some frustration
along the way) :-)
Best of luck.
Bert.
----- Original Message -----
From: <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Saturday, January 19, 2002 9:09 AM
Subject: Re: [castor-dev] mapping.xml
>
> That's not correct; the dtd does not provide all available values.
As
> an aside, I do read all available documentation before asking questions,
> including the dtd and samples.
>
> The dtd states" The field type is the proper Java class of the
field's
> value or a short name that maps to a Java class (e.g. integer or
> java.lang.Integer)."
>
>
> To those familiar with the product, that might mean something. To
someone
> new to JDBC and Caster, it might not. I fall into the later category. To
> try and clarify this I did also look at the sample mapping file. This
uses
> int and String and Vector I believe, and that's about it. From this I
> might assume that float is also valid, but what about varchar? And char?
> How are they used? I have varchar fields that vary in length from about
16
> to 3072; does that mean they need to be declared differently? And what if
> one of the fields is auto-genereated by the DB?
>
>
>
>
>
>
> Bruce Snyder
> <ferret@frii. To: [EMAIL PROTECTED]
> com> cc:
> Subject: Re: [castor-dev]
mapping.xml
> 01/18/02
> 02:16 PM
> Please
> respond to
> castor-dev
>
>
>
>
>
>
> This one time, at band camp, [EMAIL PROTECTED] said:
>
> > Does someone have a better example of one of these they could
share?
> >I'm new to JDBC, and don't understand all of the XML file. A list of
> >allowed values for the field values, for example. A better explanation
/
> >example of using object relationships.
>
> Timothy,
>
> Please see http://castor.exolab.org/mapping.dtd. This provides
> comments on all available values. Also, see src/examples/jdo/mapping.xml
> for the mapping descriptor for the CastorJDO examples.
>
> Bruce
> --
>
> perl -e 'print unpack("u30","<0G)U8V4\@4VYY9&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
>
> -----------------------------------------------------------
> If you wish to unsubscribe from this mailing, send mail to
> [EMAIL PROTECTED] with a subject of:
> unsubscribe castor-dev
<!DOCTYPE databases PUBLIC "-//EXOLAB/Castor Mapping DTD Version 1.0//EN"
"http://castor.exolab.org/mapping.dtd">
<mapping>
<class name="nz.co.webrent.services.security.entity.User" identity="id"
key-generator="UUID">
<description>Generic User</description>
<map-to table="webrent_user" />
<field name="id" type="string" required="true">
<sql name="user_id" type="varchar" />
<xml name="userId" node="attribute" />
</field>
<field name="email" type="string" required="true">
<sql name="email" type="varchar" />
<xml name="email" node="attribute" />
</field>
<field name="userName" type="string" required="true">
<sql name="user_name" type="varchar" />
<xml name="user_name" node="attribute" />
</field>
<field name="password" type="string" required="true">
<sql name="password" type="varchar" />
<xml name="password" node="attribute" />
</field>
<field name="modifiedDate" type="date" >
<sql name="modified_date" type="date" />
<xml name="modifiedDate" node="attribute" />
</field>
<field name="createDate" type="date" >
<sql name="create_date" type="date" />
<xml name="createDate" node="attribute" />
</field>
<field name="pwdModifiedDate" type="date">
<sql name="pwd_modified_date" type="date" />
<xml name="pwdModified" node="attribute" />
</field>
<field name="lastLogin" type="date">
<sql name="last_login" type="date" />
<xml name="lastLogin" node="attribute" />
</field>
<field name="confirmData" type="string">
<sql name="confirm_data" type="varchar" />
<xml name="confirmData" node="attribute" />
</field>
<field name="confirmValue" type="string">
<sql name="confirm_value" type="varchar" />
<xml name="confirmValue" node="attribute" />
</field>
<field name="firstName" type="string">
<sql name="first_name" type="varchar" />
<xml name="firstName" node="attribute" />
</field>
<field name="lastName" type="string">
<sql name="last_name" type="varchar" />
<xml name="lastName" node="attribute" />
</field>
<field name="accountStatus" type="integer">
<sql name="acc_status" type="integer" />
<xml name="accountStatus" node="attribute" />
</field>
<field name="profileId" type="string">
<sql name="profile_id" type="varchar" />
<xml name="profileId" node="attribute" />
</field>
<field name="profileClazz" type="string">
<sql name="profile_class" type="varchar" />
<xml name="profileClass" node="attribute" />
</field>
</class>
<class name="nz.co.webrent.services.security.entity.Permission" identity="id"
key-generator="UUID">
<description>Generic Permission</description>
<map-to table="webrent_permission" />
<field name="id" type="string" required="true">
<sql name="perm_id" type="varchar" />
<xml name="id" node="attribute" />
</field>
<field name="name" type="string" required="true">
<sql name="perm_name" type="varchar" />
<xml name="name" node="attribute" />
</field>
<field name="description" type="string">
<sql name="perm_desc" type="varchar" />
<xml name="description" node="attribute" />
</field>
</class>
<class name="nz.co.webrent.services.security.entity.Role" identity="id"
key-generator="UUID">
<description>Generic Role</description>
<map-to table="webrent_role" />
<field name="id" type="string" required="true">
<sql name="role_id" type="varchar" />
<xml name="id" node="attribute" />
</field>
<field name="name" type="string" required="true">
<sql name="role_name" type="varchar" />
<xml name="name" node="attribute" />
</field>
<field name="description" type="string">
<sql name="role_desc" type="varchar" />
<xml name="description" node="attribute" />
</field>
<field name="permissions" type="nz.co.webrent.services.security.entity.Permission"
required="true" collection="collection" direct="false" lazy="true"
set-method="setPermissions" get-method="getAllPermissions">
<sql name="perm_id" many-table="webrent_role_permission_map" many-key="role_id" />
<xml name="permissions" node="element" />
</field>
</class>
<class name="nz.co.webrent.services.security.entity.Group" identity="id"
key-generator="UUID">
<description>Generic Group</description>
<map-to table="webrent_group" />
<field name="id" type="string" required="true">
<sql name="group_id" type="varchar" />
<xml name="id" node="attribute" />
</field>
<field name="name" type="string" required="true">
<sql name="group_name" type="varchar" />
<xml name="name" node="attribute" />
</field>
<field name="description" type="string" required="false">
<sql name="group_desc" type="varchar" />
<xml name="description" node="attribute" />
</field>
<field name="groupRoles" type="nz.co.webrent.services.security.entity.GroupRole"
required="false" collection="collection" direct="false" lazy="false">
<sql many-key="group_id" />
<xml name="groupRoles" node="element" />
</field>
</class>
<class name="nz.co.webrent.services.security.entity.GroupRole" identity="id"
depends="nz.co.webrent.services.security.entity.Group" key-generator="UUID">
<description>Generic GroupRole</description>
<map-to table="webrent_grole" />
<field name="id" type="string" required="true">
<sql name="grole_id" type="varchar" />
<xml name="id" node="attribute" />
</field>
<field name="role" type="nz.co.webrent.services.security.entity.Role"
required="true" direct="false">
<sql name="role_id" />
<xml name="id" node="element" />
</field>
<field name="group" type="nz.co.webrent.services.security.entity.Group"
required="true" direct="false">
<sql name="group_id" />
<xml name="group" node="element" />
</field>
<field name="users" type="nz.co.webrent.services.security.entity.User"
required="false" collection="collection" direct="false" lazy="true">
<sql name="user_id" many-table="webrent_grole_user_map" many-key="grole_id" />
<xml name="users" node="element" />
</field>
</class>
</mapping>