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 St...@fws.gov on 2005/05/05 21:47:57 UTC

OJB 1.0.3 bug (with test case): Two m:n collections between same pair of classes

We have encountered another bug in 1.0.3.  We are using ODMG, though I 
suspect this one is a PB bug.  It also looks like it's related to the 
problem reported last week by Bartłomiej Knabel ("[PB] two relations 
between two classes").

Summary: I have a class "Parent" which has two separate m:n relationships 
to the same class "Child".  All entries for both relationships are always 
written to the indirection table for the first one that appears in 
repository.xml - nothing is ever written to the second indirection table. 
If I put entries in both indirection tables by hand, then the object is 
materialized correctly.

Here's a test case:

================ OjbTest.java ================

package ojbtest;

import java.util.ArrayList;
import java.util.List;

import junit.framework.Assert;
import junit.framework.Test;
import junit.framework.TestCase;

import org.apache.ojb.odmg.OJB;

import org.odmg.Database;
import org.odmg.Implementation;
import org.odmg.OQLQuery;
import org.odmg.Transaction;

public class OjbTest extends TestCase {

    private Implementation fImplementation = null;
    private Database fDatabase = null;

    public OjbTest() { }

    public void testTwoMToNOfSameClass()
        throws Exception
    {
        Transaction tx = fImplementation.newTransaction();
        tx.begin();

        Parent parent = new Parent(1);
        fDatabase.makePersistent(parent);

        Child child = new Child(20);
        fDatabase.makePersistent(child);
        List list = new ArrayList();
        list.add(child);
        parent.setChildren(list);

        child = new Child(30);
        fDatabase.makePersistent(child);
        list = new ArrayList();
        list.add(child);
        parent.setOtherChildren(list);

        tx.commit();

        // Make sure that DO's are built correctly
        Assert.assertEquals(1, parent.getChildren().size());
        Assert.assertEquals(20, ((Child) 
parent.getChildren().get(0)).getId());
        Assert.assertEquals(1, parent.getOtherChildren().size());
        Assert.assertEquals(30, ((Child) 
parent.getOtherChildren().get(0)).getId());

        // Retrieve the parent and see what we get
        tx = fImplementation.newTransaction();
        tx.begin();
        OQLQuery query = fImplementation.newOQLQuery();
        query.create("select x from ojbtest.Parent where id = 1");
        parent = (Parent) ((List) query.execute()).get(0);

        Assert.assertEquals(1, parent.getChildren().size());
        Assert.assertEquals(20, ((Child) 
parent.getChildren().get(0)).getId());
        Assert.assertEquals(1, parent.getOtherChildren().size());
        Assert.assertEquals(30, ((Child) 
parent.getOtherChildren().get(0)).getId());

        tx.commit();
    }

    protected void setUp()
                 throws Exception
    {
                 super.setUp();

        if (fImplementation == null) {
            fImplementation = OJB.getInstance();
            fDatabase = fImplementation.newDatabase();
            fDatabase.open("tails", fDatabase.OPEN_READ_WRITE);
        }
    }
}

================ Parent.java ================

package ojbtest;

import java.util.List;

public class Parent {

    private int fId;
    private List fChildren;
    private List fOtherChildren;

    public Parent() { }
    public Parent(int id) { fId = id; }

    public void setId(int id) { fId = id; }
    public int getId() { return fId; }

    public void setChildren(List list) { fChildren = list; }
    public List getChildren() { return fChildren; }

    public void setOtherChildren(List list) { fOtherChildren = list; }
    public List getOtherChildren() { return fOtherChildren; }
}

================ Child.java ================

package ojbtest;

import java.util.List;

public class Child {

    private int fId;

    public Child() { }
    public Child(int id) { fId = id; }

    public void setId(int id) { fId = id; }
    public int getId() { return fId; }
}

================ repository_user.xml ================

   <!-- - - - - - - Parent - - - - - - -->

   <class-descriptor
      class="ojbtest.Parent"
      table="PARENT" >

      <field-descriptor
         name="id"
         column="ID"
         jdbc-type="INTEGER"
         primarykey="true"
      />

      <object-cache 
class="org.apache.ojb.broker.cache.ObjectCachePerBrokerImpl" />

      <collection-descriptor
         name="children"
         element-class-ref="ojbtest.Child"
         indirection-table="PARENT_CHILD"
         auto-delete="none"
         auto-update="none" >
         <fk-pointing-to-this-class    column="PARENT_ID" />
         <fk-pointing-to-element-class column="CHILD_ID" />
      </collection-descriptor>

      <collection-descriptor
         name="otherChildren"
         element-class-ref="ojbtest.Child"
         indirection-table="OTHER_PARENT_CHILD"
         auto-delete="none"
         auto-update="none" >
         <fk-pointing-to-this-class    column="PARENT_ID" />
         <fk-pointing-to-element-class column="CHILD_ID" />
      </collection-descriptor>

   </class-descriptor>

   <!-- - - - - - - Child - - - - - - -->

   <class-descriptor
      class="ojbtest.Child"
      table="CHILD" >

      <object-cache 
class="org.apache.ojb.broker.cache.ObjectCachePerBrokerImpl" />

      <field-descriptor
         name="id"
         column="ID"
         jdbc-type="INTEGER"
         primarykey="true"
      />
   </class-descriptor>

================ schema.sql ================

create table PARENT ( ID INTEGER not null, primary key(ID) );

create table CHILD ( ID INTEGER not null, primary key(ID) );

create table PARENT_CHILD (PARENT_ID INTEGER, CHILD_ID INTEGER);

create table OTHER_PARENT_CHILD (PARENT_ID INTEGER, CHILD_ID INTEGER);

================ end ================

thanks,
-steve

Steve Clark
ECOS Development Group
steve_clark@fws.gov
(970)226-9291


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


Re: OJB 1.0.3 bug (with test case): Two m:n collections between same pair of classes

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

this is fixed in CVS (OJB_1_0_RELEASE branch, currently 
"super-reference" inheritance is not stable, some tests fail) and will 
be included in 1.0.4.

regards,
Armin

Jakob Braeuchi wrote:
> hi steve,
> 
> i did the test using ODMG M2NTest and there the actors show up in the 
> wrong collection after retrieval.
> so it looks like a bug in the ODMG part of ojb.
> 
> jakob
> 
> Jakob Braeuchi schrieb:
> 
>> hi steve,
>>
>> i extended our M2NTest (PB) and added a second relationship from Movie 
>> to Actor.
>> The movie has 3 Actors in the actors-collection and 2 Actors in the 
>> actor2-collection. After store both indirection tables are correctly 
>> filled.
>>
>>     public void doTestStoreTTXX()
>>     {
>>         String postfix = "" + System.currentTimeMillis();
>>         Movie movie = buildMovieWithActors(postfix);
>>
>>         broker.beginTransaction();
>>         broker.store(movie);
>>         broker.commitTransaction();
>>
>>         Query queryMovie = queryMovie(postfix);
>>         Collection resultMovie = broker.getCollectionByQuery(queryMovie);
>>         assertEquals(1, resultMovie.size());
>>
>>         Query queryActor = queryActor(postfix);
>>         Collection resultActor = broker.getCollectionByQuery(queryActor);
>>         assertEquals(3 + 2, resultActor.size());   <<<<<<<
>>
>>         Query queryRole = queryRole(null, movie);
>>         Collection resultRole = broker.getCollectionByQuery(queryRole);
>>         assertEquals(3, resultRole.size());
>>
>>         broker.clearCache();
>>         Identity oid = new Identity(movie, broker);
>>         Movie readMovie = (Movie) broker.getObjectByIdentity(oid);
>>         assertNotNull(readMovie);
>>         assertEquals(3, readMovie.getActors().size());
>>         assertEquals(2, readMovie.getActors2().size());  <<<<<<<
>>     }
>>
>> i have not yet tried it with your testcase.
>>
>> jakob
>>
>> Steve_Clark@fws.gov schrieb:
>>
>>> We have encountered another bug in 1.0.3.  We are using ODMG, though 
>>> I suspect this one is a PB bug.  It also looks like it's related to 
>>> the problem reported last week by Bartłomiej Knabel ("[PB] two 
>>> relations between two classes").
>>>
>>> Summary: I have a class "Parent" which has two separate m:n 
>>> relationships to the same class "Child".  All entries for both 
>>> relationships are always written to the indirection table for the 
>>> first one that appears in repository.xml - nothing is ever written to 
>>> the second indirection table. If I put entries in both indirection 
>>> tables by hand, then the object is materialized correctly.
>>>
>>> Here's a test case:
>>>
>>> ================ OjbTest.java ================
>>>
>>> package ojbtest;
>>>
>>> import java.util.ArrayList;
>>> import java.util.List;
>>>
>>> import junit.framework.Assert;
>>> import junit.framework.Test;
>>> import junit.framework.TestCase;
>>>
>>> import org.apache.ojb.odmg.OJB;
>>>
>>> import org.odmg.Database;
>>> import org.odmg.Implementation;
>>> import org.odmg.OQLQuery;
>>> import org.odmg.Transaction;
>>>
>>> public class OjbTest extends TestCase {
>>>
>>>     private Implementation fImplementation = null;
>>>     private Database fDatabase = null;
>>>
>>>     public OjbTest() { }
>>>
>>>     public void testTwoMToNOfSameClass()
>>>         throws Exception
>>>     {
>>>         Transaction tx = fImplementation.newTransaction();
>>>         tx.begin();
>>>
>>>         Parent parent = new Parent(1);
>>>         fDatabase.makePersistent(parent);
>>>
>>>         Child child = new Child(20);
>>>         fDatabase.makePersistent(child);
>>>         List list = new ArrayList();
>>>         list.add(child);
>>>         parent.setChildren(list);
>>>
>>>         child = new Child(30);
>>>         fDatabase.makePersistent(child);
>>>         list = new ArrayList();
>>>         list.add(child);
>>>         parent.setOtherChildren(list);
>>>
>>>         tx.commit();
>>>
>>>         // Make sure that DO's are built correctly
>>>         Assert.assertEquals(1, parent.getChildren().size());
>>>         Assert.assertEquals(20, ((Child) 
>>> parent.getChildren().get(0)).getId());
>>>         Assert.assertEquals(1, parent.getOtherChildren().size());
>>>         Assert.assertEquals(30, ((Child) 
>>> parent.getOtherChildren().get(0)).getId());
>>>
>>>         // Retrieve the parent and see what we get
>>>         tx = fImplementation.newTransaction();
>>>         tx.begin();
>>>         OQLQuery query = fImplementation.newOQLQuery();
>>>         query.create("select x from ojbtest.Parent where id = 1");
>>>         parent = (Parent) ((List) query.execute()).get(0);
>>>
>>>         Assert.assertEquals(1, parent.getChildren().size());
>>>         Assert.assertEquals(20, ((Child) 
>>> parent.getChildren().get(0)).getId());
>>>         Assert.assertEquals(1, parent.getOtherChildren().size());
>>>         Assert.assertEquals(30, ((Child) 
>>> parent.getOtherChildren().get(0)).getId());
>>>
>>>         tx.commit();
>>>     }
>>>
>>>     protected void setUp()
>>>                  throws Exception
>>>     {
>>>                  super.setUp();
>>>
>>>         if (fImplementation == null) {
>>>             fImplementation = OJB.getInstance();
>>>             fDatabase = fImplementation.newDatabase();
>>>             fDatabase.open("tails", fDatabase.OPEN_READ_WRITE);
>>>         }
>>>     }
>>> }
>>>
>>> ================ Parent.java ================
>>>
>>> package ojbtest;
>>>
>>> import java.util.List;
>>>
>>> public class Parent {
>>>
>>>     private int fId;
>>>     private List fChildren;
>>>     private List fOtherChildren;
>>>
>>>     public Parent() { }
>>>     public Parent(int id) { fId = id; }
>>>
>>>     public void setId(int id) { fId = id; }
>>>     public int getId() { return fId; }
>>>
>>>     public void setChildren(List list) { fChildren = list; }
>>>     public List getChildren() { return fChildren; }
>>>
>>>     public void setOtherChildren(List list) { fOtherChildren = list; }
>>>     public List getOtherChildren() { return fOtherChildren; }
>>> }
>>>
>>> ================ Child.java ================
>>>
>>> package ojbtest;
>>>
>>> import java.util.List;
>>>
>>> public class Child {
>>>
>>>     private int fId;
>>>
>>>     public Child() { }
>>>     public Child(int id) { fId = id; }
>>>
>>>     public void setId(int id) { fId = id; }
>>>     public int getId() { return fId; }
>>> }
>>>
>>> ================ repository_user.xml ================
>>>
>>>    <!-- - - - - - - Parent - - - - - - -->
>>>
>>>    <class-descriptor
>>>       class="ojbtest.Parent"
>>>       table="PARENT" >
>>>
>>>       <field-descriptor
>>>          name="id"
>>>          column="ID"
>>>          jdbc-type="INTEGER"
>>>          primarykey="true"
>>>       />
>>>
>>>       <object-cache 
>>> class="org.apache.ojb.broker.cache.ObjectCachePerBrokerImpl" />
>>>
>>>       <collection-descriptor
>>>          name="children"
>>>          element-class-ref="ojbtest.Child"
>>>          indirection-table="PARENT_CHILD"
>>>          auto-delete="none"
>>>          auto-update="none" >
>>>          <fk-pointing-to-this-class    column="PARENT_ID" />
>>>          <fk-pointing-to-element-class column="CHILD_ID" />
>>>       </collection-descriptor>
>>>
>>>       <collection-descriptor
>>>          name="otherChildren"
>>>          element-class-ref="ojbtest.Child"
>>>          indirection-table="OTHER_PARENT_CHILD"
>>>          auto-delete="none"
>>>          auto-update="none" >
>>>          <fk-pointing-to-this-class    column="PARENT_ID" />
>>>          <fk-pointing-to-element-class column="CHILD_ID" />
>>>       </collection-descriptor>
>>>
>>>    </class-descriptor>
>>>
>>>    <!-- - - - - - - Child - - - - - - -->
>>>
>>>    <class-descriptor
>>>       class="ojbtest.Child"
>>>       table="CHILD" >
>>>
>>>       <object-cache 
>>> class="org.apache.ojb.broker.cache.ObjectCachePerBrokerImpl" />
>>>
>>>       <field-descriptor
>>>          name="id"
>>>          column="ID"
>>>          jdbc-type="INTEGER"
>>>          primarykey="true"
>>>       />
>>>    </class-descriptor>
>>>
>>> ================ schema.sql ================
>>>
>>> create table PARENT ( ID INTEGER not null, primary key(ID) );
>>>
>>> create table CHILD ( ID INTEGER not null, primary key(ID) );
>>>
>>> create table PARENT_CHILD (PARENT_ID INTEGER, CHILD_ID INTEGER);
>>>
>>> create table OTHER_PARENT_CHILD (PARENT_ID INTEGER, CHILD_ID INTEGER);
>>>
>>> ================ end ================
>>>
>>> thanks,
>>> -steve
>>>
>>> Steve Clark
>>> ECOS Development Group
>>> steve_clark@fws.gov
>>> (970)226-9291
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
>>> For additional commands, e-mail: ojb-user-help@db.apache.org
>>>
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
>> For additional commands, e-mail: ojb-user-help@db.apache.org
>>
>>
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org
> 
> 
> 

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


Re: OJB 1.0.3 bug (with test case): Two m:n collections between same pair of classes

Posted by Jakob Braeuchi <jb...@gmx.ch>.
hi steve,

Jakob Braeuchi schrieb:

> hi steve,
>
> i did the test using ODMG M2NTest and there the actors show up in the 
> wrong collection after retrieval.

to be a little bit more precise: no record is written to the second 
indirection table ;)

jakob

> so it looks like a bug in the ODMG part of ojb.
>
> jakob
>
> Jakob Braeuchi schrieb:
>
>> hi steve,
>>
>> i extended our M2NTest (PB) and added a second relationship from 
>> Movie to Actor.
>> The movie has 3 Actors in the actors-collection and 2 Actors in the 
>> actor2-collection. After store both indirection tables are correctly 
>> filled.
>>
>>     public void doTestStoreTTXX()
>>     {
>>         String postfix = "" + System.currentTimeMillis();
>>         Movie movie = buildMovieWithActors(postfix);
>>
>>         broker.beginTransaction();
>>         broker.store(movie);
>>         broker.commitTransaction();
>>
>>         Query queryMovie = queryMovie(postfix);
>>         Collection resultMovie = 
>> broker.getCollectionByQuery(queryMovie);
>>         assertEquals(1, resultMovie.size());
>>
>>         Query queryActor = queryActor(postfix);
>>         Collection resultActor = 
>> broker.getCollectionByQuery(queryActor);
>>         assertEquals(3 + 2, resultActor.size());   <<<<<<<
>>
>>         Query queryRole = queryRole(null, movie);
>>         Collection resultRole = broker.getCollectionByQuery(queryRole);
>>         assertEquals(3, resultRole.size());
>>
>>         broker.clearCache();
>>         Identity oid = new Identity(movie, broker);
>>         Movie readMovie = (Movie) broker.getObjectByIdentity(oid);
>>         assertNotNull(readMovie);
>>         assertEquals(3, readMovie.getActors().size());
>>         assertEquals(2, readMovie.getActors2().size());  <<<<<<<
>>     }
>>
>> i have not yet tried it with your testcase.
>>
>> jakob
>>
>> Steve_Clark@fws.gov schrieb:
>>
>>> We have encountered another bug in 1.0.3.  We are using ODMG, though 
>>> I suspect this one is a PB bug.  It also looks like it's related to 
>>> the problem reported last week by Bartłomiej Knabel ("[PB] two 
>>> relations between two classes").
>>>
>>> Summary: I have a class "Parent" which has two separate m:n 
>>> relationships to the same class "Child".  All entries for both 
>>> relationships are always written to the indirection table for the 
>>> first one that appears in repository.xml - nothing is ever written 
>>> to the second indirection table. If I put entries in both 
>>> indirection tables by hand, then the object is materialized correctly.
>>>
>>> Here's a test case:
>>>
>>> ================ OjbTest.java ================
>>>
>>> package ojbtest;
>>>
>>> import java.util.ArrayList;
>>> import java.util.List;
>>>
>>> import junit.framework.Assert;
>>> import junit.framework.Test;
>>> import junit.framework.TestCase;
>>>
>>> import org.apache.ojb.odmg.OJB;
>>>
>>> import org.odmg.Database;
>>> import org.odmg.Implementation;
>>> import org.odmg.OQLQuery;
>>> import org.odmg.Transaction;
>>>
>>> public class OjbTest extends TestCase {
>>>
>>>     private Implementation fImplementation = null;
>>>     private Database fDatabase = null;
>>>
>>>     public OjbTest() { }
>>>
>>>     public void testTwoMToNOfSameClass()
>>>         throws Exception
>>>     {
>>>         Transaction tx = fImplementation.newTransaction();
>>>         tx.begin();
>>>
>>>         Parent parent = new Parent(1);
>>>         fDatabase.makePersistent(parent);
>>>
>>>         Child child = new Child(20);
>>>         fDatabase.makePersistent(child);
>>>         List list = new ArrayList();
>>>         list.add(child);
>>>         parent.setChildren(list);
>>>
>>>         child = new Child(30);
>>>         fDatabase.makePersistent(child);
>>>         list = new ArrayList();
>>>         list.add(child);
>>>         parent.setOtherChildren(list);
>>>
>>>         tx.commit();
>>>
>>>         // Make sure that DO's are built correctly
>>>         Assert.assertEquals(1, parent.getChildren().size());
>>>         Assert.assertEquals(20, ((Child) 
>>> parent.getChildren().get(0)).getId());
>>>         Assert.assertEquals(1, parent.getOtherChildren().size());
>>>         Assert.assertEquals(30, ((Child) 
>>> parent.getOtherChildren().get(0)).getId());
>>>
>>>         // Retrieve the parent and see what we get
>>>         tx = fImplementation.newTransaction();
>>>         tx.begin();
>>>         OQLQuery query = fImplementation.newOQLQuery();
>>>         query.create("select x from ojbtest.Parent where id = 1");
>>>         parent = (Parent) ((List) query.execute()).get(0);
>>>
>>>         Assert.assertEquals(1, parent.getChildren().size());
>>>         Assert.assertEquals(20, ((Child) 
>>> parent.getChildren().get(0)).getId());
>>>         Assert.assertEquals(1, parent.getOtherChildren().size());
>>>         Assert.assertEquals(30, ((Child) 
>>> parent.getOtherChildren().get(0)).getId());
>>>
>>>         tx.commit();
>>>     }
>>>
>>>     protected void setUp()
>>>                  throws Exception
>>>     {
>>>                  super.setUp();
>>>
>>>         if (fImplementation == null) {
>>>             fImplementation = OJB.getInstance();
>>>             fDatabase = fImplementation.newDatabase();
>>>             fDatabase.open("tails", fDatabase.OPEN_READ_WRITE);
>>>         }
>>>     }
>>> }
>>>
>>> ================ Parent.java ================
>>>
>>> package ojbtest;
>>>
>>> import java.util.List;
>>>
>>> public class Parent {
>>>
>>>     private int fId;
>>>     private List fChildren;
>>>     private List fOtherChildren;
>>>
>>>     public Parent() { }
>>>     public Parent(int id) { fId = id; }
>>>
>>>     public void setId(int id) { fId = id; }
>>>     public int getId() { return fId; }
>>>
>>>     public void setChildren(List list) { fChildren = list; }
>>>     public List getChildren() { return fChildren; }
>>>
>>>     public void setOtherChildren(List list) { fOtherChildren = list; }
>>>     public List getOtherChildren() { return fOtherChildren; }
>>> }
>>>
>>> ================ Child.java ================
>>>
>>> package ojbtest;
>>>
>>> import java.util.List;
>>>
>>> public class Child {
>>>
>>>     private int fId;
>>>
>>>     public Child() { }
>>>     public Child(int id) { fId = id; }
>>>
>>>     public void setId(int id) { fId = id; }
>>>     public int getId() { return fId; }
>>> }
>>>
>>> ================ repository_user.xml ================
>>>
>>>    <!-- - - - - - - Parent - - - - - - -->
>>>
>>>    <class-descriptor
>>>       class="ojbtest.Parent"
>>>       table="PARENT" >
>>>
>>>       <field-descriptor
>>>          name="id"
>>>          column="ID"
>>>          jdbc-type="INTEGER"
>>>          primarykey="true"
>>>       />
>>>
>>>       <object-cache 
>>> class="org.apache.ojb.broker.cache.ObjectCachePerBrokerImpl" />
>>>
>>>       <collection-descriptor
>>>          name="children"
>>>          element-class-ref="ojbtest.Child"
>>>          indirection-table="PARENT_CHILD"
>>>          auto-delete="none"
>>>          auto-update="none" >
>>>          <fk-pointing-to-this-class    column="PARENT_ID" />
>>>          <fk-pointing-to-element-class column="CHILD_ID" />
>>>       </collection-descriptor>
>>>
>>>       <collection-descriptor
>>>          name="otherChildren"
>>>          element-class-ref="ojbtest.Child"
>>>          indirection-table="OTHER_PARENT_CHILD"
>>>          auto-delete="none"
>>>          auto-update="none" >
>>>          <fk-pointing-to-this-class    column="PARENT_ID" />
>>>          <fk-pointing-to-element-class column="CHILD_ID" />
>>>       </collection-descriptor>
>>>
>>>    </class-descriptor>
>>>
>>>    <!-- - - - - - - Child - - - - - - -->
>>>
>>>    <class-descriptor
>>>       class="ojbtest.Child"
>>>       table="CHILD" >
>>>
>>>       <object-cache 
>>> class="org.apache.ojb.broker.cache.ObjectCachePerBrokerImpl" />
>>>
>>>       <field-descriptor
>>>          name="id"
>>>          column="ID"
>>>          jdbc-type="INTEGER"
>>>          primarykey="true"
>>>       />
>>>    </class-descriptor>
>>>
>>> ================ schema.sql ================
>>>
>>> create table PARENT ( ID INTEGER not null, primary key(ID) );
>>>
>>> create table CHILD ( ID INTEGER not null, primary key(ID) );
>>>
>>> create table PARENT_CHILD (PARENT_ID INTEGER, CHILD_ID INTEGER);
>>>
>>> create table OTHER_PARENT_CHILD (PARENT_ID INTEGER, CHILD_ID INTEGER);
>>>
>>> ================ end ================
>>>
>>> thanks,
>>> -steve
>>>
>>> Steve Clark
>>> ECOS Development Group
>>> steve_clark@fws.gov
>>> (970)226-9291
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
>>> For additional commands, e-mail: ojb-user-help@db.apache.org
>>>
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
>> For additional commands, e-mail: ojb-user-help@db.apache.org
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org
>
>

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


Re: OJB 1.0.3 bug (with test case): Two m:n collections between same pair of classes

Posted by Jakob Braeuchi <jb...@gmx.ch>.
hi steve,

i did the test using ODMG M2NTest and there the actors show up in the 
wrong collection after retrieval.
so it looks like a bug in the ODMG part of ojb.

jakob

Jakob Braeuchi schrieb:

> hi steve,
>
> i extended our M2NTest (PB) and added a second relationship from Movie 
> to Actor.
> The movie has 3 Actors in the actors-collection and 2 Actors in the 
> actor2-collection. After store both indirection tables are correctly 
> filled.
>
>     public void doTestStoreTTXX()
>     {
>         String postfix = "" + System.currentTimeMillis();
>         Movie movie = buildMovieWithActors(postfix);
>
>         broker.beginTransaction();
>         broker.store(movie);
>         broker.commitTransaction();
>
>         Query queryMovie = queryMovie(postfix);
>         Collection resultMovie = broker.getCollectionByQuery(queryMovie);
>         assertEquals(1, resultMovie.size());
>
>         Query queryActor = queryActor(postfix);
>         Collection resultActor = broker.getCollectionByQuery(queryActor);
>         assertEquals(3 + 2, resultActor.size());   <<<<<<<
>
>         Query queryRole = queryRole(null, movie);
>         Collection resultRole = broker.getCollectionByQuery(queryRole);
>         assertEquals(3, resultRole.size());
>
>         broker.clearCache();
>         Identity oid = new Identity(movie, broker);
>         Movie readMovie = (Movie) broker.getObjectByIdentity(oid);
>         assertNotNull(readMovie);
>         assertEquals(3, readMovie.getActors().size());
>         assertEquals(2, readMovie.getActors2().size());  <<<<<<<
>     }
>
> i have not yet tried it with your testcase.
>
> jakob
>
> Steve_Clark@fws.gov schrieb:
>
>> We have encountered another bug in 1.0.3.  We are using ODMG, though 
>> I suspect this one is a PB bug.  It also looks like it's related to 
>> the problem reported last week by Bartłomiej Knabel ("[PB] two 
>> relations between two classes").
>>
>> Summary: I have a class "Parent" which has two separate m:n 
>> relationships to the same class "Child".  All entries for both 
>> relationships are always written to the indirection table for the 
>> first one that appears in repository.xml - nothing is ever written to 
>> the second indirection table. If I put entries in both indirection 
>> tables by hand, then the object is materialized correctly.
>>
>> Here's a test case:
>>
>> ================ OjbTest.java ================
>>
>> package ojbtest;
>>
>> import java.util.ArrayList;
>> import java.util.List;
>>
>> import junit.framework.Assert;
>> import junit.framework.Test;
>> import junit.framework.TestCase;
>>
>> import org.apache.ojb.odmg.OJB;
>>
>> import org.odmg.Database;
>> import org.odmg.Implementation;
>> import org.odmg.OQLQuery;
>> import org.odmg.Transaction;
>>
>> public class OjbTest extends TestCase {
>>
>>     private Implementation fImplementation = null;
>>     private Database fDatabase = null;
>>
>>     public OjbTest() { }
>>
>>     public void testTwoMToNOfSameClass()
>>         throws Exception
>>     {
>>         Transaction tx = fImplementation.newTransaction();
>>         tx.begin();
>>
>>         Parent parent = new Parent(1);
>>         fDatabase.makePersistent(parent);
>>
>>         Child child = new Child(20);
>>         fDatabase.makePersistent(child);
>>         List list = new ArrayList();
>>         list.add(child);
>>         parent.setChildren(list);
>>
>>         child = new Child(30);
>>         fDatabase.makePersistent(child);
>>         list = new ArrayList();
>>         list.add(child);
>>         parent.setOtherChildren(list);
>>
>>         tx.commit();
>>
>>         // Make sure that DO's are built correctly
>>         Assert.assertEquals(1, parent.getChildren().size());
>>         Assert.assertEquals(20, ((Child) 
>> parent.getChildren().get(0)).getId());
>>         Assert.assertEquals(1, parent.getOtherChildren().size());
>>         Assert.assertEquals(30, ((Child) 
>> parent.getOtherChildren().get(0)).getId());
>>
>>         // Retrieve the parent and see what we get
>>         tx = fImplementation.newTransaction();
>>         tx.begin();
>>         OQLQuery query = fImplementation.newOQLQuery();
>>         query.create("select x from ojbtest.Parent where id = 1");
>>         parent = (Parent) ((List) query.execute()).get(0);
>>
>>         Assert.assertEquals(1, parent.getChildren().size());
>>         Assert.assertEquals(20, ((Child) 
>> parent.getChildren().get(0)).getId());
>>         Assert.assertEquals(1, parent.getOtherChildren().size());
>>         Assert.assertEquals(30, ((Child) 
>> parent.getOtherChildren().get(0)).getId());
>>
>>         tx.commit();
>>     }
>>
>>     protected void setUp()
>>                  throws Exception
>>     {
>>                  super.setUp();
>>
>>         if (fImplementation == null) {
>>             fImplementation = OJB.getInstance();
>>             fDatabase = fImplementation.newDatabase();
>>             fDatabase.open("tails", fDatabase.OPEN_READ_WRITE);
>>         }
>>     }
>> }
>>
>> ================ Parent.java ================
>>
>> package ojbtest;
>>
>> import java.util.List;
>>
>> public class Parent {
>>
>>     private int fId;
>>     private List fChildren;
>>     private List fOtherChildren;
>>
>>     public Parent() { }
>>     public Parent(int id) { fId = id; }
>>
>>     public void setId(int id) { fId = id; }
>>     public int getId() { return fId; }
>>
>>     public void setChildren(List list) { fChildren = list; }
>>     public List getChildren() { return fChildren; }
>>
>>     public void setOtherChildren(List list) { fOtherChildren = list; }
>>     public List getOtherChildren() { return fOtherChildren; }
>> }
>>
>> ================ Child.java ================
>>
>> package ojbtest;
>>
>> import java.util.List;
>>
>> public class Child {
>>
>>     private int fId;
>>
>>     public Child() { }
>>     public Child(int id) { fId = id; }
>>
>>     public void setId(int id) { fId = id; }
>>     public int getId() { return fId; }
>> }
>>
>> ================ repository_user.xml ================
>>
>>    <!-- - - - - - - Parent - - - - - - -->
>>
>>    <class-descriptor
>>       class="ojbtest.Parent"
>>       table="PARENT" >
>>
>>       <field-descriptor
>>          name="id"
>>          column="ID"
>>          jdbc-type="INTEGER"
>>          primarykey="true"
>>       />
>>
>>       <object-cache 
>> class="org.apache.ojb.broker.cache.ObjectCachePerBrokerImpl" />
>>
>>       <collection-descriptor
>>          name="children"
>>          element-class-ref="ojbtest.Child"
>>          indirection-table="PARENT_CHILD"
>>          auto-delete="none"
>>          auto-update="none" >
>>          <fk-pointing-to-this-class    column="PARENT_ID" />
>>          <fk-pointing-to-element-class column="CHILD_ID" />
>>       </collection-descriptor>
>>
>>       <collection-descriptor
>>          name="otherChildren"
>>          element-class-ref="ojbtest.Child"
>>          indirection-table="OTHER_PARENT_CHILD"
>>          auto-delete="none"
>>          auto-update="none" >
>>          <fk-pointing-to-this-class    column="PARENT_ID" />
>>          <fk-pointing-to-element-class column="CHILD_ID" />
>>       </collection-descriptor>
>>
>>    </class-descriptor>
>>
>>    <!-- - - - - - - Child - - - - - - -->
>>
>>    <class-descriptor
>>       class="ojbtest.Child"
>>       table="CHILD" >
>>
>>       <object-cache 
>> class="org.apache.ojb.broker.cache.ObjectCachePerBrokerImpl" />
>>
>>       <field-descriptor
>>          name="id"
>>          column="ID"
>>          jdbc-type="INTEGER"
>>          primarykey="true"
>>       />
>>    </class-descriptor>
>>
>> ================ schema.sql ================
>>
>> create table PARENT ( ID INTEGER not null, primary key(ID) );
>>
>> create table CHILD ( ID INTEGER not null, primary key(ID) );
>>
>> create table PARENT_CHILD (PARENT_ID INTEGER, CHILD_ID INTEGER);
>>
>> create table OTHER_PARENT_CHILD (PARENT_ID INTEGER, CHILD_ID INTEGER);
>>
>> ================ end ================
>>
>> thanks,
>> -steve
>>
>> Steve Clark
>> ECOS Development Group
>> steve_clark@fws.gov
>> (970)226-9291
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
>> For additional commands, e-mail: ojb-user-help@db.apache.org
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org
>
>

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


Re: OJB 1.0.3 bug (with test case): Two m:n collections between same pair of classes

Posted by Jakob Braeuchi <jb...@gmx.ch>.
hi steve,

i extended our M2NTest (PB) and added a second relationship from Movie 
to Actor.
The movie has 3 Actors in the actors-collection and 2 Actors in the 
actor2-collection. After store both indirection tables are correctly filled.

     public void doTestStoreTTXX()
     {
         String postfix = "" + System.currentTimeMillis();
         Movie movie = buildMovieWithActors(postfix);

         broker.beginTransaction();
         broker.store(movie);
         broker.commitTransaction();

         Query queryMovie = queryMovie(postfix);
         Collection resultMovie = broker.getCollectionByQuery(queryMovie);
         assertEquals(1, resultMovie.size());

         Query queryActor = queryActor(postfix);
         Collection resultActor = broker.getCollectionByQuery(queryActor);
         assertEquals(3 + 2, resultActor.size());   <<<<<<<

         Query queryRole = queryRole(null, movie);
         Collection resultRole = broker.getCollectionByQuery(queryRole);
         assertEquals(3, resultRole.size());

         broker.clearCache();
         Identity oid = new Identity(movie, broker);
         Movie readMovie = (Movie) broker.getObjectByIdentity(oid);
         assertNotNull(readMovie);
         assertEquals(3, readMovie.getActors().size());
         assertEquals(2, readMovie.getActors2().size());  <<<<<<<
     }

i have not yet tried it with your testcase.

jakob

Steve_Clark@fws.gov schrieb:
> We have encountered another bug in 1.0.3.  We are using ODMG, though I 
> suspect this one is a PB bug.  It also looks like it's related to the 
> problem reported last week by Bartłomiej Knabel ("[PB] two relations 
> between two classes").
> 
> Summary: I have a class "Parent" which has two separate m:n relationships 
> to the same class "Child".  All entries for both relationships are always 
> written to the indirection table for the first one that appears in 
> repository.xml - nothing is ever written to the second indirection table. 
> If I put entries in both indirection tables by hand, then the object is 
> materialized correctly.
> 
> Here's a test case:
> 
> ================ OjbTest.java ================
> 
> package ojbtest;
> 
> import java.util.ArrayList;
> import java.util.List;
> 
> import junit.framework.Assert;
> import junit.framework.Test;
> import junit.framework.TestCase;
> 
> import org.apache.ojb.odmg.OJB;
> 
> import org.odmg.Database;
> import org.odmg.Implementation;
> import org.odmg.OQLQuery;
> import org.odmg.Transaction;
> 
> public class OjbTest extends TestCase {
> 
>     private Implementation fImplementation = null;
>     private Database fDatabase = null;
> 
>     public OjbTest() { }
> 
>     public void testTwoMToNOfSameClass()
>         throws Exception
>     {
>         Transaction tx = fImplementation.newTransaction();
>         tx.begin();
> 
>         Parent parent = new Parent(1);
>         fDatabase.makePersistent(parent);
> 
>         Child child = new Child(20);
>         fDatabase.makePersistent(child);
>         List list = new ArrayList();
>         list.add(child);
>         parent.setChildren(list);
> 
>         child = new Child(30);
>         fDatabase.makePersistent(child);
>         list = new ArrayList();
>         list.add(child);
>         parent.setOtherChildren(list);
> 
>         tx.commit();
> 
>         // Make sure that DO's are built correctly
>         Assert.assertEquals(1, parent.getChildren().size());
>         Assert.assertEquals(20, ((Child) 
> parent.getChildren().get(0)).getId());
>         Assert.assertEquals(1, parent.getOtherChildren().size());
>         Assert.assertEquals(30, ((Child) 
> parent.getOtherChildren().get(0)).getId());
> 
>         // Retrieve the parent and see what we get
>         tx = fImplementation.newTransaction();
>         tx.begin();
>         OQLQuery query = fImplementation.newOQLQuery();
>         query.create("select x from ojbtest.Parent where id = 1");
>         parent = (Parent) ((List) query.execute()).get(0);
> 
>         Assert.assertEquals(1, parent.getChildren().size());
>         Assert.assertEquals(20, ((Child) 
> parent.getChildren().get(0)).getId());
>         Assert.assertEquals(1, parent.getOtherChildren().size());
>         Assert.assertEquals(30, ((Child) 
> parent.getOtherChildren().get(0)).getId());
> 
>         tx.commit();
>     }
> 
>     protected void setUp()
>                  throws Exception
>     {
>                  super.setUp();
> 
>         if (fImplementation == null) {
>             fImplementation = OJB.getInstance();
>             fDatabase = fImplementation.newDatabase();
>             fDatabase.open("tails", fDatabase.OPEN_READ_WRITE);
>         }
>     }
> }
> 
> ================ Parent.java ================
> 
> package ojbtest;
> 
> import java.util.List;
> 
> public class Parent {
> 
>     private int fId;
>     private List fChildren;
>     private List fOtherChildren;
> 
>     public Parent() { }
>     public Parent(int id) { fId = id; }
> 
>     public void setId(int id) { fId = id; }
>     public int getId() { return fId; }
> 
>     public void setChildren(List list) { fChildren = list; }
>     public List getChildren() { return fChildren; }
> 
>     public void setOtherChildren(List list) { fOtherChildren = list; }
>     public List getOtherChildren() { return fOtherChildren; }
> }
> 
> ================ Child.java ================
> 
> package ojbtest;
> 
> import java.util.List;
> 
> public class Child {
> 
>     private int fId;
> 
>     public Child() { }
>     public Child(int id) { fId = id; }
> 
>     public void setId(int id) { fId = id; }
>     public int getId() { return fId; }
> }
> 
> ================ repository_user.xml ================
> 
>    <!-- - - - - - - Parent - - - - - - -->
> 
>    <class-descriptor
>       class="ojbtest.Parent"
>       table="PARENT" >
> 
>       <field-descriptor
>          name="id"
>          column="ID"
>          jdbc-type="INTEGER"
>          primarykey="true"
>       />
> 
>       <object-cache 
> class="org.apache.ojb.broker.cache.ObjectCachePerBrokerImpl" />
> 
>       <collection-descriptor
>          name="children"
>          element-class-ref="ojbtest.Child"
>          indirection-table="PARENT_CHILD"
>          auto-delete="none"
>          auto-update="none" >
>          <fk-pointing-to-this-class    column="PARENT_ID" />
>          <fk-pointing-to-element-class column="CHILD_ID" />
>       </collection-descriptor>
> 
>       <collection-descriptor
>          name="otherChildren"
>          element-class-ref="ojbtest.Child"
>          indirection-table="OTHER_PARENT_CHILD"
>          auto-delete="none"
>          auto-update="none" >
>          <fk-pointing-to-this-class    column="PARENT_ID" />
>          <fk-pointing-to-element-class column="CHILD_ID" />
>       </collection-descriptor>
> 
>    </class-descriptor>
> 
>    <!-- - - - - - - Child - - - - - - -->
> 
>    <class-descriptor
>       class="ojbtest.Child"
>       table="CHILD" >
> 
>       <object-cache 
> class="org.apache.ojb.broker.cache.ObjectCachePerBrokerImpl" />
> 
>       <field-descriptor
>          name="id"
>          column="ID"
>          jdbc-type="INTEGER"
>          primarykey="true"
>       />
>    </class-descriptor>
> 
> ================ schema.sql ================
> 
> create table PARENT ( ID INTEGER not null, primary key(ID) );
> 
> create table CHILD ( ID INTEGER not null, primary key(ID) );
> 
> create table PARENT_CHILD (PARENT_ID INTEGER, CHILD_ID INTEGER);
> 
> create table OTHER_PARENT_CHILD (PARENT_ID INTEGER, CHILD_ID INTEGER);
> 
> ================ end ================
> 
> thanks,
> -steve
> 
> Steve Clark
> ECOS Development Group
> steve_clark@fws.gov
> (970)226-9291
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org
> 
> 

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