Apache JDO Project - equivalent mappings of join condition?

This is Interesting: Free IT Magazines  
Home > Archive > Apache JDO Project > July 2005 > equivalent mappings of join condition?





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author equivalent mappings of join condition?
Michelle Caisse

2005-07-20, 5:45 pm

Hi,

Are the following mappings equivalent? They differ in the placement of
the <join> element.

Mapping 1:
<class name="Person" table="persons">
<datastore-identity strategy="identity"
column="DATASTORE_IDENTITY"/>
<inheritance strategy="new-table">
<discriminator strategy="class-name"
column="DISCRIMINATOR"/>
</inheritance>
<join column="EMPID" table="employee_phoneno_type"/>
<field name="personid" column="PERSONID"/>
<field name="firstname" column="FIRSTNAME"/>
<field name="lastname" column="LASTNAME"/>
<field name="middlename" column="MIDDLENAME"/>
<field name="address">
<embedded null-indicator-column="COUNTRY">
<field name="addrid" column="ADDRID"/>
<field name="street" column="STREET"/>
<field name="city" column="CITY"/>
<field name="state" column="STATE"/>
<field name="zipcode" column="ZIPCODE"/>
<field name="country" column="COUNTRY"/>
</embedded>
</field>
<field name="phoneNumbers" table="employee_phoneno_type" >
<key column="TYPE"/>
<value column="PHONENO"/>
</field>
</class>

Mapping 2:
<class name="Person" table="persons">
<datastore-identity strategy="identity"
column="DATASTORE_IDENTITY"/>
<inheritance strategy="new-table">
<discriminator strategy="class-name"
column="DISCRIMINATOR"/>
</inheritance>
<field name="personid" column="PERSONID"/>
<field name="firstname" column="FIRSTNAME"/>
<field name="lastname" column="LASTNAME"/>
<field name="middlename" column="MIDDLENAME"/>
<field name="address">
<embedded null-indicator-column="COUNTRY">
<field name="addrid" column="ADDRID"/>
<field name="street" column="STREET"/>
<field name="city" column="CITY"/>
<field name="state" column="STATE"/>
<field name="zipcode" column="ZIPCODE"/>
<field name="country" column="COUNTRY"/>
</embedded>
</field>
<field name="phoneNumbers" table="employee_phoneno_type" >
<join column="EMPID"/>
<key column="TYPE"/>
<value column="PHONENO"/>
</field>
</class>

JPOX appears to treat them differently. When mapping 1 is used, an
apparent attempt to insert values (nulls) into the employee_phoneno_type
table results in an error: "ERROR 23502: Column 'PHONENO' cannot accept
a NULL value". Mapping 2 executes without error.

-- Michelle

Andy Jefferson

2005-07-21, 7:45 am

Hi Michelle,

> Are the following mappings equivalent? They differ in the placement of
> the <join> element.


Seem different to me, but since we weren't involved in the design of the ORM
we only have the spec to go by here

> Mapping 1:
> <class name="Person" table="persons">
> <join column="EMPID" table="employee_phoneno_type"/>
> <field name="phoneNumbers" table="employee_phoneno_type" >
> <key column="TYPE"/>
> <value column="PHONENO"/>
> </field>
> </class>
>
> Mapping 2:
> <class name="Person" table="persons">
> <field name="phoneNumbers" table="employee_phoneno_type" >
> <join column="EMPID"/>
> <key column="TYPE"/>
> <value column="PHONENO"/>
> </field>
> </class>
>
> JPOX appears to treat them differently.


All in the JPOX docs :-

Mapping 1 has a "Secondary Table" (spec section 15.2), which has nothing in it
- well it has a Map, but the Map has no columns of its own, so the Secondary
Table just has a PK. The Map in Mapping 1 is a "ForeignKey" Map (since
there's no <join> within <field> - meaning that the keys/values are stored in
the value table.
See here http://www.jpox.org/docs/1_1/secondary_tables.html
and here http://www.jpox.org/docs/1_1/relati...map.html#fk_uni

In Mapping 2, the Map is a "JoinTable" Map (since there's a <join> within the
<field> ) - meaning that the Map has its key and value (or FK equivalents if
the key/value are PC) stored in the join table.
See here http://www.jpox.org/docs/1_1/relati...html#join_pc_pc


Again, this comes down to the interpretation of the <join> within <field>.
Since JPOX (and other JDO impls for that matter) supports having Maps formed
with a FK in the value, we interpret the lack of a <join> within the <field>
as saying that we should store the linkage between map and value as a FK in
the value (This is consistent with Collections where there is no <join>
within <field> being interpreted as having a FK in the element).

Criticise away ;-)


It's good to see that the TCK is flushing out all possible differences of
interpretation in ORM. There are so many ways of representing relationships,
and JPOX supports what our users feel are the most common.

--
Andy

Michael Watzek

2005-07-21, 7:45 am

Hi Michelle,

the two mappings differ in the presence of the join condition. They
would be equivalent, if there is a default for the <join> element which
is "EMPID".

Michael and I looked into the spec. We could not find a default for the
<join> element, neither in chapter 15.2 (Join Condition) nor in chapter
18.8 (ELEMENT join). Thus, I conclude that there is no default.

For this reason, I do not consider both mappings equivalent and you
would have to use mapping 2. However, if mapping 1 is used then it would
be nice to receive a different exception, e.g.
JDOUserException("Unsupported mapping for field Person.phoneNumbers:
missing <join> element.").

Regards,
Michael

> Hi,
>
> Are the following mappings equivalent? They differ in the placement of
> the <join> element.
>
> Mapping 1:
> <class name="Person" table="persons">
> <datastore-identity strategy="identity"
> column="DATASTORE_IDENTITY"/>
> <inheritance strategy="new-table">
> <discriminator strategy="class-name"
> column="DISCRIMINATOR"/>
> </inheritance>
> <join column="EMPID" table="employee_phoneno_type"/>
> <field name="personid" column="PERSONID"/>
> <field name="firstname" column="FIRSTNAME"/>
> <field name="lastname" column="LASTNAME"/>
> <field name="middlename" column="MIDDLENAME"/>
> <field name="address">
> <embedded null-indicator-column="COUNTRY">
> <field name="addrid" column="ADDRID"/>
> <field name="street" column="STREET"/>
> <field name="city" column="CITY"/>
> <field name="state" column="STATE"/>
> <field name="zipcode" column="ZIPCODE"/>
> <field name="country" column="COUNTRY"/>
> </embedded>
> </field>
> <field name="phoneNumbers" table="employee_phoneno_type" >
> <key column="TYPE"/>
> <value column="PHONENO"/>
> </field>
> </class>
>
> Mapping 2:
> <class name="Person" table="persons">
> <datastore-identity strategy="identity"
> column="DATASTORE_IDENTITY"/>
> <inheritance strategy="new-table">
> <discriminator strategy="class-name"
> column="DISCRIMINATOR"/>
> </inheritance>
> <field name="personid" column="PERSONID"/>
> <field name="firstname" column="FIRSTNAME"/>
> <field name="lastname" column="LASTNAME"/>
> <field name="middlename" column="MIDDLENAME"/>
> <field name="address">
> <embedded null-indicator-column="COUNTRY">
> <field name="addrid" column="ADDRID"/>
> <field name="street" column="STREET"/>
> <field name="city" column="CITY"/>
> <field name="state" column="STATE"/>
> <field name="zipcode" column="ZIPCODE"/>
> <field name="country" column="COUNTRY"/>
> </embedded>
> </field>
> <field name="phoneNumbers" table="employee_phoneno_type" >
> <join column="EMPID"/>
> <key column="TYPE"/>
> <value column="PHONENO"/>
> </field>
> </class>
>
> JPOX appears to treat them differently. When mapping 1 is used, an
> apparent attempt to insert values (nulls) into the employee_phoneno_type
> table results in an error: "ERROR 23502: Column 'PHONENO' cannot accept
> a NULL value". Mapping 2 executes without error.
>
> -- Michelle



--
-------------------------------------------------------------------
Michael Watzek Tech@Spree Engineering GmbH
mailto:mwa.tech@spree.de Buelowstr. 66
Tel.: ++49/30/235 520 36 10783 Berlin - Germany
Fax.: ++49/30/217 520 12 http://www.spree.de/
-------------------------------------------------------------------

Michelle Caisse

2005-07-21, 5:45 pm

Thanks, Andy. Makes sense. Nice docs!

-- Michelle

Andy Jefferson wrote:

>Hi Michelle,
>
>
>
>
>Seem different to me, but since we weren't involved in the design of the ORM
>we only have the spec to go by here
>
>
>
>
>All in the JPOX docs :-
>
>Mapping 1 has a "Secondary Table" (spec section 15.2), which has nothing in it
>- well it has a Map, but the Map has no columns of its own, so the Secondary
>Table just has a PK. The Map in Mapping 1 is a "ForeignKey" Map (since
>there's no <join> within <field> - meaning that the keys/values are stored in
>the value table.
>See here http://www.jpox.org/docs/1_1/secondary_tables.html
>and here http://www.jpox.org/docs/1_1/relati...map.html#fk_uni
>
>In Mapping 2, the Map is a "JoinTable" Map (since there's a <join> within the
><field> ) - meaning that the Map has its key and value (or FK equivalents if
>the key/value are PC) stored in the join table.
>See here http://www.jpox.org/docs/1_1/relati...html#join_pc_pc
>
>
>Again, this comes down to the interpretation of the <join> within <field>.
>Since JPOX (and other JDO impls for that matter) supports having Maps formed
>with a FK in the value, we interpret the lack of a <join> within the <field>
>as saying that we should store the linkage between map and value as a FK in
>the value (This is consistent with Collections where there is no <join>
>within <field> being interpreted as having a FK in the element).
>
>Criticise away ;-)
>
>
>It's good to see that the TCK is flushing out all possible differences of
>interpretation in ORM. There are so many ways of representing relationships,
>and JPOX supports what our users feel are the most common.
>
>
>



Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com