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 Bradford Pielech <br...@alphatech.com> on 2004/06/23 01:18:35 UTC

Both sides of M:N mapping not correctly retrieved in rc7

Hello again:

	I have encountered an issue with the recursive graph structure that I 
asked about a couple of weeks ago.  Below is a snippet from the 
repository.xml.  Basically I have a DAGNode that has a list of parents and 
a list of children.  I am able to get everything loaded in OJB correctly, 
however I have a problem when I retrieve the objects.  Say, I have a 
DAGNode A and B where A is the parent and B is the child. I then store A 
and B in the DB.  When I retrieve A, A's child list correctly has B, but 
B's parent list contains 1 object that is null.  So if I call 
B.getParents().size(), it returns 1, but the only value in there is a 
null.  Conversely, if I retrieve B, B's parent list is correct, but A's 
child list has 1 entry that is a null.

Any ideas what is going on?

thanks!
Brad

repository_user.xml
----------------------------
<class-descriptor
     class="SimpleDAGNode"
     table="effect"
 >
     <field-descriptor
         name="ID"
         column="ebo_id"
         jdbc-type="VARCHAR"
         primarykey="true"
         length="35"
     >
     </field-descriptor>
     <collection-descriptor
         name="children"
         collection-class="org.apache.ojb.broker.util.collections.ManageableArrayList" 

         element-class-ref="SimpleDAGNode"
         indirection-table="parent_children_table"
         auto-retrieve="true"
         auto-update="none"
         auto-delete="none"
     >
         <fk-pointing-to-this-class column="parent_id"/>
         <fk-pointing-to-element-class column="child_id"/>
     </collection-descriptor>

     <collection-descriptor
         name="parents"
         element-class-ref="SimpleDAGNode"
         collection-class="org.apache.ojb.broker.util.collections.ManageableArrayList"
         indirection-table="parent_children_table"
         auto-retrieve="true"
         auto-update="none"
         auto-delete="none"
     >
         <fk-pointing-to-this-class column="child_id"/>
         <fk-pointing-to-element-class column="parent_id"/>
     </collection-descriptor>
</class-descriptor>
--------------------

Relevant other settings:

PersistentFieldClass=org.apache.ojb.broker.metadata.fieldaccess.PersistentFieldDirectAccessImpl
ObjectCacheClass=org.apache.ojb.broker.cache.ObjectCachePerBrokerImpl

using rc7 downloaded from website



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


Re: Both sides of M:N mapping not correctly retrieved in rc7

Posted by Bradford Pielech <br...@alphatech.com>.
Armin:

         Thanks a lot for the help.  It works now.  In addition to what you 
pointed out, I also had a bug on my side related to interfaces and extents 
that caused OJB to get confused when connecting collections.

thanks again,
Brad


I also noticed the problem with the
At 08:32 PM 6/23/2004 +0200, you wrote:

>Hi Brad,
>
>good news! Seems to work.
>
>I checked in a new test case show how to use PB-api to 
>store/retrieve/delete object hierarchies via m:n relation with different 
>collection-descriptor auto-xxx settings.
>
>Main difference to your test is that I use two table (one for tree object, 
>the other as indirection table). But it should also be possible to map 
>this stuff in one table (not recommended IMO, because it will mix 
>different types of rows).
>
>The test is called "M2NGraphTest.java" (see test-suite, [db-ojb]/src/test) 
>and is a little different from yours, but following the example should 
>make work your test too.
>
>http://cvs.apache.org/viewcvs.cgi/db-ojb/src/test/org/apache/ojb/broker/M2NGraphTest.java?rev=1.1&view=markup
>
>The metadata mapping can be found in
>src/test/org/apache/ojb repository_junit_reference.xml
>
>By the way, your wrapper methods addEntity, linkEntity use different PB 
>instances, thus two connections will be used. If linkEntity fails the 
>changes made in addEntity will not be rollback. And you don't close the 
>used PB instance.
>But maybe you override this methods in your wrapper too, so my notice is 
>wrong ;-)
>
>regards,
>Armin
>
>Bradford Pielech wrote:
>
>>yeah, those are basically wrappers to underlying broker methods.
>>The addEntity method is a wrapper for the following method that accesses 
>>the persistence broker:
>>----------------------------
>>public boolean addEntity(SimpleDagNode nodeA) throws Exception {
>>     PersistenceBroker pbroker = 
>> PersistenceBrokerFactory.defaultPersistenceBroker();
>>       pbroker.beginTransaction();
>>       pbroker.store(nodeA, modificationType);
>>       pbroker.commitTransaction();
>>     return true;
>>----------------------------
>>
>>and broker.linkEntity is implemented as follows:
>>----------------------------
>>  public void linkEntity(SimpleDagNode parent, SimpleDagNode child) 
>> throws Exception {
>>    if(!parent.getChildren().contains(child)){
>>      parent.addChild(child);
>>    }
>>      PersistenceBroker pbroker = 
>> PersistenceBrokerFactory.defaultPersistenceBroker();
>>       pbroker.beginTransaction();
>>       pbroker.serviceBrokerHelper().link(o, false);
>>       pbroker.commitTransaction();
>>}
>>----------------------------
>>At 03:05 PM 6/23/2004 +0200, you wrote:
>>
>>>seems you use an user specific PersistenceBroker implementation, can you 
>>>post methods
>>>
>>>broker.addEntity(nodeA);
>>>broker.linkEntity(nodeA, nodeB);
>>>
>>>too.
>>>
>>>regards,
>>>Armin
>>>
>>>Bradford Pielech wrote:
>>>
>>>>Oops, just realized there was a logic bug in the junit test that makes 
>>>>the code incorrect because I had to quickly rewrite the test to remove 
>>>>unneeded subclasses and such.  Here is the correct version:
>>>>public void testAddNewChild() throws Exception {
>>>>     SimpleDAGNode nodeA = new nodeANode();
>>>>     SimpleDAGNode nodeB = new nodeBNode();
>>>>     //store nodeA first
>>>>     broker.addEntity(nodeA);
>>>>     //then store the nodeB
>>>>     broker.addEntity(nodeB);
>>>>    //make A the parent of B because they are not linked in the code 
>>>> automatically
>>>>     broker.linkEntity(nodeA, nodeB);
>>>>     SimpleDAGNode retrievednodeB = broker.getEntity(nodeB.getID());
>>>>     assertNotNull("Verifying the nodeB was retrieved", retrievednodeB);
>>>>     SimpleDAGNode retrievednodeA = (SimpleDAGNode) 
>>>> retrievednodeB.getParentAt(0);
>>>>     assertEquals("verify the nodeA was stored", nodeA.getID(),
>>>>                  retrievednodeA.getEboId());
>>>>     assertEquals("verify the retrieved nodeA has 1 child (the nodeB)", 1,
>>>>                  retrievednodeA.getChildCount());
>>>>     assertEquals("verify the retrieved nodeB has 1 parent (the nodeA)", 1,
>>>>                  retrievednodeB.getParentCount());
>>>>     assertEquals(
>>>>         "verify, using hashcode, that the nodeB's parent is the nodeA",
>>>>         retrievednodeA.hashCode(),
>>>>         retrievednodeB.getParentAt(0).hashCode());
>>>>     for (Iterator i = retrievednodeA.getChildren().iterator(); 
>>>> i.hasNext(); ) {
>>>>       Object o = i.next();
>>>>       //this next test fails because the child is null
>>>>       assertNotNull("Verifying nodeA's children are not null", o);
>>>>       assertEquals(
>>>>           "verify, using hashcode, that the nodeAs child is the nodeB",
>>>>           retrievednodeB.hashCode(), o.hashCode());
>>>>     }
>>>>   }
>>>>
>>>>
>>>>At 08:18 AM 6/23/2004 -0400, you wrote:
>>>>
>>>>>Armin:
>>>>>
>>>>>         Sure, no problem. Apologies for the formatting, but the basic 
>>>>> idea should be clear. I also attached my OJB.properties and 
>>>>> repository_user.xml.
>>>>>
>>>>>thanks!
>>>>>Brad
>>>>>
>>>>>
>>>>>SimpleDagNode class:
>>>>>---------------------------------------
>>>>>public class SimpleDAGNode{
>>>>>
>>>>>   private List children;
>>>>>   private String ID;
>>>>>   private List parents;
>>>>>
>>>>>   public SimpleDAGNode() {
>>>>>     ID = "";
>>>>>     parents = new Vector();
>>>>>     children = new Vector();
>>>>>   }
>>>>>   public String getID() {
>>>>>     return ID;
>>>>>   }
>>>>>   public void addChildNode(DAGNode child) {
>>>>>     // Cannot add same child twice
>>>>>     if (!children.contains(child)) {
>>>>>       children.add(child);
>>>>>       if (!child.getParents().contains(this)) {
>>>>>         child.getParents().add(this);
>>>>>       }
>>>>>
>>>>>     }
>>>>>
>>>>>   }
>>>>>   public void removeChild(DAGNode child) {
>>>>>     children.remove(child);
>>>>>     child.getParents().remove(this);
>>>>>   }
>>>>>
>>>>>   public List getParents() {
>>>>>     return parents;
>>>>>   }
>>>>>
>>>>>   public List getChildren() {
>>>>>     return children;
>>>>>   }
>>>>>
>>>>>  public boolean equals(Object ref) {
>>>>>      if (ref == null) {
>>>>>        return false;
>>>>>      }
>>>>>      if (ref instanceof SimpleDagNode) {
>>>>>        return (getID().equals( ( (SimpleDagNode) ref).getID()));
>>>>>      }
>>>>>      else {
>>>>>        return false;
>>>>>      }
>>>>>    }
>>>>>}



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


Re: Both sides of M:N mapping not correctly retrieved in rc7

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

good news! Seems to work.

I checked in a new test case show how to use PB-api to 
store/retrieve/delete object hierarchies via m:n relation with different 
collection-descriptor auto-xxx settings.

Main difference to your test is that I use two table (one for tree 
object, the other as indirection table). But it should also be possible 
to map this stuff in one table (not recommended IMO, because it will mix 
different types of rows).

The test is called "M2NGraphTest.java" (see test-suite, 
[db-ojb]/src/test) and is a little different from yours, but following 
the example should make work your test too.

http://cvs.apache.org/viewcvs.cgi/db-ojb/src/test/org/apache/ojb/broker/M2NGraphTest.java?rev=1.1&view=markup

The metadata mapping can be found in
src/test/org/apache/ojb repository_junit_reference.xml

By the way, your wrapper methods addEntity, linkEntity use different PB 
instances, thus two connections will be used. If linkEntity fails the 
changes made in addEntity will not be rollback. And you don't close the 
used PB instance.
But maybe you override this methods in your wrapper too, so my notice is 
wrong ;-)

regards,
Armin

Bradford Pielech wrote:

> yeah, those are basically wrappers to underlying broker methods.
> 
> The addEntity method is a wrapper for the following method that accesses 
> the persistence broker:
> ----------------------------
> public boolean addEntity(SimpleDagNode nodeA) throws Exception {
>     PersistenceBroker pbroker = 
> PersistenceBrokerFactory.defaultPersistenceBroker();
>       pbroker.beginTransaction();
>       pbroker.store(nodeA, modificationType);
>       pbroker.commitTransaction();
>     return true;
> ----------------------------
> 
> 
> 
> and broker.linkEntity is implemented as follows:
> ----------------------------
>  public void linkEntity(SimpleDagNode parent, SimpleDagNode child) 
> throws Exception {
>    if(!parent.getChildren().contains(child)){
>      parent.addChild(child);
>    }
>      PersistenceBroker pbroker = 
> PersistenceBrokerFactory.defaultPersistenceBroker();
>       pbroker.beginTransaction();
>       pbroker.serviceBrokerHelper().link(o, false);
>       pbroker.commitTransaction();
> }
> ----------------------------
> 
> At 03:05 PM 6/23/2004 +0200, you wrote:
> 
>> seems you use an user specific PersistenceBroker implementation, can 
>> you post methods
>>
>> broker.addEntity(nodeA);
>> broker.linkEntity(nodeA, nodeB);
>>
>> too.
>>
>> regards,
>> Armin
>>
>> Bradford Pielech wrote:
>>
>>> Oops, just realized there was a logic bug in the junit test that 
>>> makes the code incorrect because I had to quickly rewrite the test to 
>>> remove unneeded subclasses and such.  Here is the correct version:
>>> public void testAddNewChild() throws Exception {
>>>     SimpleDAGNode nodeA = new nodeANode();
>>>     SimpleDAGNode nodeB = new nodeBNode();
>>>     //store nodeA first
>>>     broker.addEntity(nodeA);
>>>     //then store the nodeB
>>>     broker.addEntity(nodeB);
>>>    //make A the parent of B because they are not linked in the code 
>>> automatically
>>>     broker.linkEntity(nodeA, nodeB);
>>>     SimpleDAGNode retrievednodeB = broker.getEntity(nodeB.getID());
>>>     assertNotNull("Verifying the nodeB was retrieved", retrievednodeB);
>>>     SimpleDAGNode retrievednodeA = (SimpleDAGNode) 
>>> retrievednodeB.getParentAt(0);
>>>     assertEquals("verify the nodeA was stored", nodeA.getID(),
>>>                  retrievednodeA.getEboId());
>>>     assertEquals("verify the retrieved nodeA has 1 child (the 
>>> nodeB)", 1,
>>>                  retrievednodeA.getChildCount());
>>>     assertEquals("verify the retrieved nodeB has 1 parent (the 
>>> nodeA)", 1,
>>>                  retrievednodeB.getParentCount());
>>>     assertEquals(
>>>         "verify, using hashcode, that the nodeB's parent is the nodeA",
>>>         retrievednodeA.hashCode(),
>>>         retrievednodeB.getParentAt(0).hashCode());
>>>     for (Iterator i = retrievednodeA.getChildren().iterator(); 
>>> i.hasNext(); ) {
>>>       Object o = i.next();
>>>       //this next test fails because the child is null
>>>       assertNotNull("Verifying nodeA's children are not null", o);
>>>       assertEquals(
>>>           "verify, using hashcode, that the nodeAs child is the nodeB",
>>>           retrievednodeB.hashCode(), o.hashCode());
>>>     }
>>>   }
>>>
>>>
>>> At 08:18 AM 6/23/2004 -0400, you wrote:
>>>
>>>> Armin:
>>>>
>>>>         Sure, no problem. Apologies for the formatting, but the 
>>>> basic idea should be clear. I also attached my OJB.properties and 
>>>> repository_user.xml.
>>>>
>>>> thanks!
>>>> Brad
>>>>
>>>>
>>>> SimpleDagNode class:
>>>> ---------------------------------------
>>>> public class SimpleDAGNode{
>>>>
>>>>   private List children;
>>>>   private String ID;
>>>>   private List parents;
>>>>
>>>>   public SimpleDAGNode() {
>>>>     ID = "";
>>>>     parents = new Vector();
>>>>     children = new Vector();
>>>>   }
>>>>   public String getID() {
>>>>     return ID;
>>>>   }
>>>>   public void addChildNode(DAGNode child) {
>>>>     // Cannot add same child twice
>>>>     if (!children.contains(child)) {
>>>>       children.add(child);
>>>>       if (!child.getParents().contains(this)) {
>>>>         child.getParents().add(this);
>>>>       }
>>>>
>>>>     }
>>>>
>>>>   }
>>>>   public void removeChild(DAGNode child) {
>>>>     children.remove(child);
>>>>     child.getParents().remove(this);
>>>>   }
>>>>
>>>>   public List getParents() {
>>>>     return parents;
>>>>   }
>>>>
>>>>   public List getChildren() {
>>>>     return children;
>>>>   }
>>>>
>>>>  public boolean equals(Object ref) {
>>>>      if (ref == null) {
>>>>        return false;
>>>>      }
>>>>      if (ref instanceof SimpleDagNode) {
>>>>        return (getID().equals( ( (SimpleDagNode) ref).getID()));
>>>>      }
>>>>      else {
>>>>        return false;
>>>>      }
>>>>    }
>>>> }
>>>
>>>
>>>
>>> ---------------------------------------------------------------------
>>> 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: Both sides of M:N mapping not correctly retrieved in rc7

Posted by Bradford Pielech <br...@alphatech.com>.
yeah, those are basically wrappers to underlying broker methods.

The addEntity method is a wrapper for the following method that accesses 
the persistence broker:
----------------------------
public boolean addEntity(SimpleDagNode nodeA) throws Exception {
     PersistenceBroker pbroker = 
PersistenceBrokerFactory.defaultPersistenceBroker();
       pbroker.beginTransaction();
       pbroker.store(nodeA, modificationType);
       pbroker.commitTransaction();
     return true;
----------------------------



and broker.linkEntity is implemented as follows:
----------------------------
  public void linkEntity(SimpleDagNode parent, SimpleDagNode child) throws 
Exception {
    if(!parent.getChildren().contains(child)){
      parent.addChild(child);
    }
      PersistenceBroker pbroker = 
PersistenceBrokerFactory.defaultPersistenceBroker();
       pbroker.beginTransaction();
       pbroker.serviceBrokerHelper().link(o, false);
       pbroker.commitTransaction();
}
----------------------------

At 03:05 PM 6/23/2004 +0200, you wrote:

>seems you use an user specific PersistenceBroker implementation, can you 
>post methods
>
>broker.addEntity(nodeA);
>broker.linkEntity(nodeA, nodeB);
>
>too.
>
>regards,
>Armin
>
>Bradford Pielech wrote:
>>Oops, just realized there was a logic bug in the junit test that makes 
>>the code incorrect because I had to quickly rewrite the test to remove 
>>unneeded subclasses and such.  Here is the correct version:
>>public void testAddNewChild() throws Exception {
>>     SimpleDAGNode nodeA = new nodeANode();
>>     SimpleDAGNode nodeB = new nodeBNode();
>>     //store nodeA first
>>     broker.addEntity(nodeA);
>>     //then store the nodeB
>>     broker.addEntity(nodeB);
>>    //make A the parent of B because they are not linked in the code 
>> automatically
>>     broker.linkEntity(nodeA, nodeB);
>>     SimpleDAGNode retrievednodeB = broker.getEntity(nodeB.getID());
>>     assertNotNull("Verifying the nodeB was retrieved", retrievednodeB);
>>     SimpleDAGNode retrievednodeA = (SimpleDAGNode) 
>> retrievednodeB.getParentAt(0);
>>     assertEquals("verify the nodeA was stored", nodeA.getID(),
>>                  retrievednodeA.getEboId());
>>     assertEquals("verify the retrieved nodeA has 1 child (the nodeB)", 1,
>>                  retrievednodeA.getChildCount());
>>     assertEquals("verify the retrieved nodeB has 1 parent (the nodeA)", 1,
>>                  retrievednodeB.getParentCount());
>>     assertEquals(
>>         "verify, using hashcode, that the nodeB's parent is the nodeA",
>>         retrievednodeA.hashCode(),
>>         retrievednodeB.getParentAt(0).hashCode());
>>     for (Iterator i = retrievednodeA.getChildren().iterator(); 
>> i.hasNext(); ) {
>>       Object o = i.next();
>>       //this next test fails because the child is null
>>       assertNotNull("Verifying nodeA's children are not null", o);
>>       assertEquals(
>>           "verify, using hashcode, that the nodeAs child is the nodeB",
>>           retrievednodeB.hashCode(), o.hashCode());
>>     }
>>   }
>>
>>
>>At 08:18 AM 6/23/2004 -0400, you wrote:
>>
>>>Armin:
>>>
>>>         Sure, no problem. Apologies for the formatting, but the basic 
>>> idea should be clear. I also attached my OJB.properties and 
>>> repository_user.xml.
>>>
>>>thanks!
>>>Brad
>>>
>>>
>>>SimpleDagNode class:
>>>---------------------------------------
>>>public class SimpleDAGNode{
>>>
>>>   private List children;
>>>   private String ID;
>>>   private List parents;
>>>
>>>   public SimpleDAGNode() {
>>>     ID = "";
>>>     parents = new Vector();
>>>     children = new Vector();
>>>   }
>>>   public String getID() {
>>>     return ID;
>>>   }
>>>   public void addChildNode(DAGNode child) {
>>>     // Cannot add same child twice
>>>     if (!children.contains(child)) {
>>>       children.add(child);
>>>       if (!child.getParents().contains(this)) {
>>>         child.getParents().add(this);
>>>       }
>>>
>>>     }
>>>
>>>   }
>>>   public void removeChild(DAGNode child) {
>>>     children.remove(child);
>>>     child.getParents().remove(this);
>>>   }
>>>
>>>   public List getParents() {
>>>     return parents;
>>>   }
>>>
>>>   public List getChildren() {
>>>     return children;
>>>   }
>>>
>>>  public boolean equals(Object ref) {
>>>      if (ref == null) {
>>>        return false;
>>>      }
>>>      if (ref instanceof SimpleDagNode) {
>>>        return (getID().equals( ( (SimpleDagNode) ref).getID()));
>>>      }
>>>      else {
>>>        return false;
>>>      }
>>>    }
>>>}
>>
>>
>>---------------------------------------------------------------------
>>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: Both sides of M:N mapping not correctly retrieved in rc7

Posted by Armin Waibel <ar...@apache.org>.
seems you use an user specific PersistenceBroker implementation, can you 
post methods

broker.addEntity(nodeA);
broker.linkEntity(nodeA, nodeB);

too.

regards,
Armin

Bradford Pielech wrote:
> Oops, just realized there was a logic bug in the junit test that makes 
> the code incorrect because I had to quickly rewrite the test to remove 
> unneeded subclasses and such.  Here is the correct version:
> 
> public void testAddNewChild() throws Exception {
> 
>     SimpleDAGNode nodeA = new nodeANode();
>     SimpleDAGNode nodeB = new nodeBNode();
>     //store nodeA first
>     broker.addEntity(nodeA);
>     //then store the nodeB
>     broker.addEntity(nodeB);
>    //make A the parent of B because they are not linked in the code 
> automatically
>     broker.linkEntity(nodeA, nodeB);
> 
>     SimpleDAGNode retrievednodeB = broker.getEntity(nodeB.getID());
>     assertNotNull("Verifying the nodeB was retrieved", retrievednodeB);
>     SimpleDAGNode retrievednodeA = (SimpleDAGNode) 
> retrievednodeB.getParentAt(0);
>     assertEquals("verify the nodeA was stored", nodeA.getID(),
>                  retrievednodeA.getEboId());
>     assertEquals("verify the retrieved nodeA has 1 child (the nodeB)", 1,
>                  retrievednodeA.getChildCount());
>     assertEquals("verify the retrieved nodeB has 1 parent (the nodeA)", 1,
>                  retrievednodeB.getParentCount());
>     assertEquals(
>         "verify, using hashcode, that the nodeB's parent is the nodeA",
>         retrievednodeA.hashCode(),
>         retrievednodeB.getParentAt(0).hashCode());
>     for (Iterator i = retrievednodeA.getChildren().iterator(); 
> i.hasNext(); ) {
>       Object o = i.next();
>       //this next test fails because the child is null
>       assertNotNull("Verifying nodeA's children are not null", o);
>       assertEquals(
>           "verify, using hashcode, that the nodeAs child is the nodeB",
>           retrievednodeB.hashCode(), o.hashCode());
>     }
>   }
> 
> 
> 
> 
> At 08:18 AM 6/23/2004 -0400, you wrote:
> 
>> Armin:
>>
>>         Sure, no problem. Apologies for the formatting, but the basic 
>> idea should be clear. I also attached my OJB.properties and 
>> repository_user.xml.
>>
>> thanks!
>> Brad
>>
>>
>> SimpleDagNode class:
>> ---------------------------------------
>> public class SimpleDAGNode{
>>
>>   private List children;
>>   private String ID;
>>   private List parents;
>>
>>   public SimpleDAGNode() {
>>     ID = "";
>>     parents = new Vector();
>>     children = new Vector();
>>   }
>>   public String getID() {
>>     return ID;
>>   }
>>   public void addChildNode(DAGNode child) {
>>     // Cannot add same child twice
>>     if (!children.contains(child)) {
>>       children.add(child);
>>       if (!child.getParents().contains(this)) {
>>         child.getParents().add(this);
>>       }
>>
>>     }
>>
>>   }
>>   public void removeChild(DAGNode child) {
>>     children.remove(child);
>>     child.getParents().remove(this);
>>   }
>>
>>   public List getParents() {
>>     return parents;
>>   }
>>
>>   public List getChildren() {
>>     return children;
>>   }
>>
>>  public boolean equals(Object ref) {
>>      if (ref == null) {
>>        return false;
>>      }
>>      if (ref instanceof SimpleDagNode) {
>>        return (getID().equals( ( (SimpleDagNode) ref).getID()));
>>      }
>>      else {
>>        return false;
>>      }
>>    }
>> }
> 
> 
> 
> 
> 
> ---------------------------------------------------------------------
> 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: Both sides of M:N mapping not correctly retrieved in rc7

Posted by Bradford Pielech <br...@alphatech.com>.
Oops, just realized there was a logic bug in the junit test that makes the 
code incorrect because I had to quickly rewrite the test to remove unneeded 
subclasses and such.  Here is the correct version:

public void testAddNewChild() throws Exception {

     SimpleDAGNode nodeA = new nodeANode();
     SimpleDAGNode nodeB = new nodeBNode();
     //store nodeA first
     broker.addEntity(nodeA);
     //then store the nodeB
     broker.addEntity(nodeB);
    //make A the parent of B because they are not linked in the code 
automatically
     broker.linkEntity(nodeA, nodeB);

     SimpleDAGNode retrievednodeB = broker.getEntity(nodeB.getID());
     assertNotNull("Verifying the nodeB was retrieved", retrievednodeB);
     SimpleDAGNode retrievednodeA = (SimpleDAGNode) 
retrievednodeB.getParentAt(0);
     assertEquals("verify the nodeA was stored", nodeA.getID(),
                  retrievednodeA.getEboId());
     assertEquals("verify the retrieved nodeA has 1 child (the nodeB)", 1,
                  retrievednodeA.getChildCount());
     assertEquals("verify the retrieved nodeB has 1 parent (the nodeA)", 1,
                  retrievednodeB.getParentCount());
     assertEquals(
         "verify, using hashcode, that the nodeB's parent is the nodeA",
         retrievednodeA.hashCode(),
         retrievednodeB.getParentAt(0).hashCode());
     for (Iterator i = retrievednodeA.getChildren().iterator(); 
i.hasNext(); ) {
       Object o = i.next();
       //this next test fails because the child is null
       assertNotNull("Verifying nodeA's children are not null", o);
       assertEquals(
           "verify, using hashcode, that the nodeAs child is the nodeB",
           retrievednodeB.hashCode(), o.hashCode());
     }
   }




At 08:18 AM 6/23/2004 -0400, you wrote:

>Armin:
>
>         Sure, no problem. Apologies for the formatting, but the basic 
> idea should be clear. I also attached my OJB.properties and 
> repository_user.xml.
>
>thanks!
>Brad
>
>
>SimpleDagNode class:
>---------------------------------------
>public class SimpleDAGNode{
>
>   private List children;
>   private String ID;
>   private List parents;
>
>   public SimpleDAGNode() {
>     ID = "";
>     parents = new Vector();
>     children = new Vector();
>   }
>   public String getID() {
>     return ID;
>   }
>   public void addChildNode(DAGNode child) {
>     // Cannot add same child twice
>     if (!children.contains(child)) {
>       children.add(child);
>       if (!child.getParents().contains(this)) {
>         child.getParents().add(this);
>       }
>
>     }
>
>   }
>   public void removeChild(DAGNode child) {
>     children.remove(child);
>     child.getParents().remove(this);
>   }
>
>   public List getParents() {
>     return parents;
>   }
>
>   public List getChildren() {
>     return children;
>   }
>
>  public boolean equals(Object ref) {
>      if (ref == null) {
>        return false;
>      }
>      if (ref instanceof SimpleDagNode) {
>        return (getID().equals( ( (SimpleDagNode) ref).getID()));
>      }
>      else {
>        return false;
>      }
>    }
>}




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


Re: Both sides of M:N mapping not correctly retrieved in rc7

Posted by Bradford Pielech <br...@alphatech.com>.
Armin:

	Sure, no problem. Apologies for the formatting, but the basic idea should 
be clear. I also attached my OJB.properties and repository_user.xml.

thanks!
Brad


SimpleDagNode class:
---------------------------------------
public class SimpleDAGNode{

   private List children;
   private String ID;
   private List parents;

   public SimpleDAGNode() {
     ID = "";
     parents = new Vector();
     children = new Vector();
   }
   public String getID() {
     return ID;
   }
   public void addChildNode(DAGNode child) {
     // Cannot add same child twice
     if (!children.contains(child)) {
       children.add(child);
       if (!child.getParents().contains(this)) {
         child.getParents().add(this);
       }

     }

   }
   public void removeChild(DAGNode child) {
     children.remove(child);
     child.getParents().remove(this);
   }

   public List getParents() {
     return parents;
   }

   public List getChildren() {
     return children;
   }

  public boolean equals(Object ref) {
      if (ref == null) {
        return false;
      }
      if (ref instanceof SimpleDagNode) {
        return (getID().equals( ( (SimpleDagNode) ref).getID()));
      }
      else {
        return false;
      }
    }
}
-------------------------------------------------------

Junit Test:


public void testAddNewChild() throws Exception {
     logger.info("Testing persisting a relationship");

     SimpleDagNode nodeA = new SimpleDagNode();
     SimpleDagNode nodeB = new SimpleDagNode();
     //store nodeA first
     broker.addEntity(nodeA);
     //then store the nodeB
     broker.addEntity(nodeB );
     broker.linkEntity(nodeA, nodeB);

     SimpleDagNode retrievedA = broker.retrieve(nodeA.getID());
     SimpleDagNode retrievedB = (SimpleDagNode) retrievedA.getParents().get(0);
     assertEquals("verify the nodeA was stored", nodeA.getD(),
                  retrievedA .getID());
     assertEquals("verify the retrieved A has 1 child", 1,
                  retrievedA.getChildren().size());
     assertEquals("verify the retrieved B has 1 parent", 1,
                  retrievedB .getParents().get(0));
     assertEquals(
         "verify, using hashcode, that the B's parent is A",
         retrievedA.hashCode(),
         retrievedB.getParents().get(0).hashCode());

     for (Iterator i = retrievedA.getChildren().iterator(); i.hasNext(); ) {
       Object o = i.next();
       /**
        * This next line fails.  Even though A has 1 child (verified 
above), its child is null
        */	
       assertNotNull("Verifying A's children are not null", 
o);
       assertEquals(
           "verify, using hashcode, that the A's child is B",
           retrievedB.hashCode(), o.hashCode());
     }
   }





Re: Both sides of M:N mapping not correctly retrieved in rc7

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

could you please send a junit test or a code snip to reproduce this 
behavior? I will integrate your test to test-suite.

regards,
Armin

Bradford Pielech wrote:

> Hello again:
> 
>     I have encountered an issue with the recursive graph structure that 
> I asked about a couple of weeks ago.  Below is a snippet from the 
> repository.xml.  Basically I have a DAGNode that has a list of parents 
> and a list of children.  I am able to get everything loaded in OJB 
> correctly, however I have a problem when I retrieve the objects.  Say, I 
> have a DAGNode A and B where A is the parent and B is the child. I then 
> store A and B in the DB.  When I retrieve A, A's child list correctly 
> has B, but B's parent list contains 1 object that is null.  So if I call 
> B.getParents().size(), it returns 1, but the only value in there is a 
> null.  Conversely, if I retrieve B, B's parent list is correct, but A's 
> child list has 1 entry that is a null.
> 
> Any ideas what is going on?
> 
> thanks!
> Brad
> 
> repository_user.xml
> ----------------------------
> <class-descriptor
>     class="SimpleDAGNode"
>     table="effect"
>  >
>     <field-descriptor
>         name="ID"
>         column="ebo_id"
>         jdbc-type="VARCHAR"
>         primarykey="true"
>         length="35"
>     >
>     </field-descriptor>
>     <collection-descriptor
>         name="children"
>         
> collection-class="org.apache.ojb.broker.util.collections.ManageableArrayList" 
> 
>         element-class-ref="SimpleDAGNode"
>         indirection-table="parent_children_table"
>         auto-retrieve="true"
>         auto-update="none"
>         auto-delete="none"
>     >
>         <fk-pointing-to-this-class column="parent_id"/>
>         <fk-pointing-to-element-class column="child_id"/>
>     </collection-descriptor>
> 
>     <collection-descriptor
>         name="parents"
>         element-class-ref="SimpleDAGNode"
>         
> collection-class="org.apache.ojb.broker.util.collections.ManageableArrayList" 
> 
>         indirection-table="parent_children_table"
>         auto-retrieve="true"
>         auto-update="none"
>         auto-delete="none"
>     >
>         <fk-pointing-to-this-class column="child_id"/>
>         <fk-pointing-to-element-class column="parent_id"/>
>     </collection-descriptor>
> </class-descriptor>
> --------------------
> 
> Relevant other settings:
> 
> PersistentFieldClass=org.apache.ojb.broker.metadata.fieldaccess.PersistentFieldDirectAccessImpl 
> 
> ObjectCacheClass=org.apache.ojb.broker.cache.ObjectCachePerBrokerImpl
> 
> using rc7 downloaded from website
> 
> 
> 
> ---------------------------------------------------------------------
> 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