db-jdo-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Eric Samson" <eric.sam...@xcalia.com>
Subject RE: Setting a 1:1 association with "mapped-by"
Date Wed, 17 May 2006 16:55:28 GMT
In particular, I'd expect a2 not pointing to b2 anymore, as this clearly is supposed to be
is a 1:1 relationship. The implementation can determine this being a 1:1 association, as there
are two corresponding fields, and consequently it should issue 

 

 

Bu default, there is no 1:1 relationships either in Java or in RDBMS.

If you want to insure this 1:1 bi-directional link you have to:

*	use some triggers in your db
*	use a JDO callback
*	do it cleanly in your set /getters in Java
*	use an ORM tool that can manage 1:1 bi-directional links

 

Best Regards,

....: Eric Samson, Founder & CTO, xcalia

Service your Data!

________________________________

De : Jörg von Frantzius [mailto:joerg.von.frantzius@artnology.com] 
Envoyé : mercredi 17 mai 2006 17:40
À : Apache JDO project
Cc : JDO Expert Group
Objet : Setting a 1:1 association with "mapped-by"

 

Hello JDO experts,

when writing some JUnit test today I came across an interesting phenomenon. I have two classes
A and B with a 1:1 association between them. The FK is put on class A, and the corresponding
field on B has "mapped-by" with the corresponding field on A (see metadata below).

Now when I have the following object graph:

 

and perform the operation

a1.setB_1to1(b2)

then I'd expect the object graph to look like the following:

 

In particular, I'd expect a2 not pointing to b2 anymore, as this clearly is supposed to be
is a 1:1 relationship. The implementation can determine this being a 1:1 association, as there
are two corresponding fields, and consequently it should issue 

"UPDATE A SET B_1TO1_FK=NULL WHERE B_1TO1_FK=2" 

before 

"UPDATE A SET B_1TO1_FK=2 WHERE ID=1" 

to keep this being a 1:1 association. 

However, what I end up with in the database is:

 

Does this really work as expected?

Here's the metadata:

        <class name="A" identity-type="application" table="A" detachable="true"
             objectid-class="javax.jdo.identity.LongIdentity" 
            persistence-modifier="persistence-capable">
            <inheritance strategy="new-table"/>
            <version strategy="version-number" column="jdoversion"/> 
            <field name="id" primary-key="true" persistence-modifier="persistent" value-strategy="sequence"
sequence="A_SEQ" >
                <extension vendor-name="jpox" key="key-database-cache-size" value="100"/>
            </field>
       
            <field name="b_1to1" column="b_1to1_FK" 
                persistence-modifier="persistent" >
            </field>                
        </class>

        <class name="B" identity-type="application" table="B" detachable="true"
             objectid-class="javax.jdo.identity.LongIdentity" 
            persistence-modifier="persistence-capable">
            <inheritance strategy="new-table"/>
            <version strategy="version-number" column="jdoversion"/> 
            <field name="id" primary-key="true" persistence-modifier="persistent" value-strategy="sequence"
sequence="B_SEQ" >
                <extension vendor-name="jpox" key="key-database-cache-size" value="100"/>
            </field>
       
            <field name="a_1to1" mapped-by="b_1to1" 
                persistence-modifier="persistent" >
            </field>                
        </class>


Regards,
Jörg

P.S.
I hope the pictures survived...


Mime
  • Unnamed multipart/related (inline, None, 0 bytes)
View raw message