You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-user@db.apache.org by Bartłomiej Knabel <ba...@gmail.com> on 2005/05/02 01:02:02 UTC

Re[2]: [PB] two relations between two classes

Hi,

I still didn't solve this poroblem.
I don't know why in one table there is allways NULL value.

I is just depending on saving order. I tried to use
auto-save="object/reference/true", but all the times one table
contains null.

Is there any possibility to have two relations between two classes
(one 1:1 and one 1:n)?

-- 
Greetings,
 Bartłomiej Knabel


---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org


Re[2]: [PB] two relations between two classes

Posted by Bartłomiej Knabel <ba...@gmail.com>.
Hi!

AW> Could you post the source code of your test case?

Here are my mapping files :

<!--Czesc atomowa-->
<class-descriptor class="com.bimki.oo7j.ojb.om.CzescAtomowa" 
        table="CzescAtomowa">
        <field-descriptor name="id" column="cza_id" jdbc-type="INTEGER"
                primarykey="true" autoincrement="true" />
        <field-descriptor column="cza_x" name="x" jdbc-type="INTEGER"></field-descriptor>
        <field-descriptor column="cza_y" name="y" jdbc-type="INTEGER"></field-descriptor>
        <field-descriptor column="cza_dokId" name="dokId" jdbc-type="INTEGER"></field-descriptor>
        <!-- relacja 1:m  z czescia zlozona -->
        <field-descriptor column="cza_czId" name="czescZlozona_id"
                jdbc-type="INTEGER"></field-descriptor>
        <reference-descriptor name="czescZlozona" auto-update="link"
                class-ref="com.bimki.oo7j.ojb.om.CzescZlozona">
                <foreignkey field-ref="czescZlozona_id" />
        </reference-descriptor>         
        <!-- relacja 1:m  z polaczeniem -->
        <collection-descriptor name="polaczenieDo"
                element-class-ref="com.bimki.oo7j.ojb.om.Polaczenie">
                <inverse-foreignkey field-ref="doatomowej_id" />
        </collection-descriptor>
        <!-- relacja 1:m  z polaczeniem -->
        <collection-descriptor name="polaczenieZ"
                element-class-ref="com.bimki.oo7j.ojb.om.Polaczenie">
                <inverse-foreignkey field-ref="zatomowej_id" />
        </collection-descriptor>        
        <reference-descriptor name="super" 
                class-ref="com.bimki.oo7j.ojb.om.ElementProjektowy" 
                auto-retrieve="true" auto-update="true" auto-delete="true">
                <foreignkey field-ref="id" />
        </reference-descriptor>
</class-descriptor>

--------------------------------------------------------------
here is CzescAtomowa class :

public class CzescAtomowa extends com.bimki.oo7j.ojb.om.ElementProjektowy
                implements java.io.Serializable {

        // Fields
        private java.lang.Integer x;
        private java.lang.Integer id;
        private java.lang.Integer czescZlozona_id;
        private java.lang.Integer y;
        private java.lang.Integer dokId;
        private com.bimki.oo7j.ojb.om.CzescZlozona czescZlozona;
        private java.util.Collection polaczenieDo = new ArrayList();
        private java.util.Collection polaczenieZ = new ArrayList();
...
//getters, setters


--------------------------------------------------------------

<!--Czesc zlozona-->
<class-descriptor class="com.bimki.oo7j.ojb.om.CzescZlozona" 
        table="CzescZlozona">
        <field-descriptor name="id" column="czz_id" jdbc-type="INTEGER" 
                primarykey="true" autoincrement="true"/>
        <!-- relacja 1:m  z czescia atomowa -->
        <collection-descriptor name="czesciAtomowe" auto-update="link"
                element-class-ref="com.bimki.oo7j.ojb.om.CzescAtomowa">
                <inverse-foreignkey field-ref="czescZlozona_id" />
        </collection-descriptor>
        <!-- relacja 1:1  z czescia atomowa -->
        <field-descriptor column="czz_glAtid" name="glownaAtomowa_id"
                jdbc-type="INTEGER"></field-descriptor>         
        <reference-descriptor name="glownaAtomowa" auto-update="true"
                class-ref="com.bimki.oo7j.ojb.om.CzescAtomowa">                         
                <foreignkey field-ref="glownaAtomowa_id" />
        </reference-descriptor>
        <!-- relacja 1:1  z dokumentem -->
        <field-descriptor column="czz_dokId" name="dokument_id" jdbc-type="INTEGER"></field-descriptor>
        <reference-descriptor name="dokument" auto-update="true"
                class-ref="com.bimki.oo7j.ojb.om.Dokument">
                <foreignkey field-ref="dokument_id" />
        </reference-descriptor>
        <!-- relacja m:n  z Zestawem podstawowym (dzielace) -->
        <collection-descriptor name="zestawyPodstawoweDzielace" auto-delete="true"
                collection-class="org.apache.ojb.broker.util.collections.ManageableArrayList" 
                element-class-ref="com.bimki.oo7j.ojb.om.ZestawPodstawowy" 
                auto-retrieve="true" auto-update="true" indirection-table="zp_czzd">
                <fk-pointing-to-this-class column="czz_zp_czpIdd" />
                <fk-pointing-to-element-class column="czz_zp_zpIdd" />
        </collection-descriptor>
        <!-- relacja m:n  z Zestawem podstawowym (nie dzielace) -->
        <collection-descriptor name="zestawyPodstawoweNieDzielace" auto-delete="true"
                collection-class="org.apache.ojb.broker.util.collections.ManageableArrayList" 
                element-class-ref="com.bimki.oo7j.ojb.om.ZestawPodstawowy" 
                auto-retrieve="true" auto-update="true" indirection-table="zp_czznd">
                <fk-pointing-to-this-class column="czz_zp_zpIdnd" />
                <fk-pointing-to-element-class column="czz_zp_czpIdnd" />
        </collection-descriptor>
        <reference-descriptor name="super" 
                class-ref="com.bimki.oo7j.ojb.om.ElementProjektowy" 
                auto-retrieve="true" auto-update="true" auto-delete="true">
                <foreignkey field-ref="id" />
        </reference-descriptor>
</class-descriptor>

--------------------------------------------------------------
here is CzescZlozona class :

public class CzescZlozona extends com.bimki.oo7j.ojb.om.ElementProjektowy implements java.io.Serializable {

    // Fields    

    private java.util.Collection zestawyPodstawoweNieDzielace = new ArrayList();
        private java.util.Collection zestawyPodstawoweDzielace = new ArrayList();
    private com.bimki.oo7j.ojb.om.Dokument dokument;
    private com.bimki.oo7j.ojb.om.CzescAtomowa glownaAtomowa;
    private java.util.Collection czesciAtomowe = new ArrayList();
        private java.lang.Integer id;
        private java.lang.Integer glownaAtomowa_id;
        private java.lang.Integer dokument_id;
//getters, setters



============================================
my sample test case :

                CzescZlozona czz = new CzescZlozona(Util.getRandomType(), Util
                                .getRandomDate(1997, 1999), null, null, new ArrayList(),
                                new ArrayList(), new ArrayList());
                broker.store(dok);

                CzescAtomowa[] czesciAtomowe = new CzescAtomowa[IloscCzANaCzZ];
                for (int i = 0; i < IloscCzANaCzZ; i++) {
                        CzescAtomowa czAtomowa = new CzescAtomowa(Util.getRandomDate(1997,
                                        2005), Util.getRandomInt(1, 9999), Util.getRandomInt(1,
                                        9999), Util.getRandomInt(1, 9999), new ArrayList(),
                                        new ArrayList());
                        czAtomowa.setTyp(Util.getRandomType());
                        czesciAtomowe[i] = czAtomowa;
                }
                czz.setDokument(dok);
                dok.setCzescZlozona(czz);
                for (int i = 0; i < IloscCzANaCzZ; i++) {
                        czesciAtomowe[i].setCzescZlozona(czz);
                }

                czz.setGlownaAtomowa(czesciAtomowe[0]);
                broker.store(czz);

                for (int i = 0; i < IloscCzANaCzZ; i++) {
                        broker.store(czesciAtomowe[i]);
                }

after commiting this case, czescAtomowa[0] has value with negative
sign :

+--------+--------+--------+-----------+----------+
| cza_id | cza_x  | cza_y  | cza_dokId | cza_czId |
+--------+--------+--------+-----------+----------+
|      1 |   2453 |   8717 |      8338 |       -4 | //here should be 2
|      4 |   1791 |   2567 |       941 |        2 |
|      5 |   7420 |   2185 |      3971 |        2 |
|      6 |    544 |   3685 |      5896 |        2 |
|      7 |   1302 |   1985 |      1284 |        2 |
|      8 |   1120 |   8319 |      4884 |        2 |
|      9 |   6646 |   9965 |      9977 |        2 |
|     10 |   9574 |   3504 |      8128 |        2 |
|     11 |   4194 |   6567 |      9490 |        2 |
+--------+--------+--------+-----------+----------+

rest of data in database looks fine.

-- 
Greetings,
 Bartłomiej Knabel


---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org


Re[2]: [PB] two relations between two classes

Posted by Bartłomiej Knabel <ba...@gmail.com>.
Hi,

should I look for the solution in metadata or in my java-code? What do
You think?

-- 
Greetings,
 Bartłomiej Knabel


---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org


Re: [PB] two relations between two classes

Posted by Armin Waibel <ar...@apache.org>.
Hi,

Bartłomiej Knabel wrote:
> Hi,
> 
> I still didn't solve this poroblem.
> I don't know why in one table there is allways NULL value.
> 
> I is just depending on saving order. I tried to use
> auto-save="object/reference/true", but all the times one table
> contains null.
> 
> Is there any possibility to have two relations between two classes
> (one 1:1 and one 1:n)?

This shouldn't be a problem I think. Did you always set all referenced 
objects in both directions before store? E.g. in CzescAtomowa is a 1:1 
reference to CzescZlozona, in CzescZlozona are a 1:1 and a 1:n reference 
to CzescAtomowa.

Could you post the source code of your test case?

regards,
Armin


---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org