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 Roland Vecera <ro...@gmx.at> on 2003/09/02 10:49:04 UTC

Newbie Problem 1:n Mapping

 
Hey!
 
I'm using db-ojb-1.0.rc3.jar and have a curious problem with
1:n-Mapping!
 
I'm working on two Relations "task" and "thread"; task includes an 1:n
mapping to "thread"!
 
Problem:
 
When I try to get a Collection of all/some specific Objects from "task",
I get exactly one Object in the Collection!
 
But, after deleting the 1:n-Mapping between Task and Thread in the
repository-user.xml, I receive the right number of Objects in my
Collection!!!
 
I have no more clue what could be wrong! Please help me!
 
 
********************************** OJB TASK shorted
Version*****************************************************
<class-descriptor
    class="info.oswp.model.Task"
    table="task"
>
    <field-descriptor
        name="id"
        column="id"
        jdbc-type="INTEGER"
        primarykey="true"
        autoincrement="true"
        sequence-name="all_sequence"
    >    
    </field-descriptor>
 
    <field-descriptor
        name="parenttask_id"
        column="parenttask_id"
        jdbc-type="INTEGER"
    >
    </field-descriptor>
 
    <field-descriptor
        name="name"
        column="name"
        jdbc-type="VARCHAR"
        length="255"
    >
    </field-descriptor>
    ...
    <collection-descriptor                                       //If I
delete this collection-descriptor, I get 
        name="relatingThreads"                                   //the
right number of Objects!!
        element-class-ref="info.oswp.model.forum.Thread"
    >
        <inverse-foreignkey field-ref="task_id"/>
    </collection-descriptor>
</class-descriptor>
 
*****************OJB THREAD shorted version ****************************
<class-descriptor
    class="info.oswp.model.forum.Thread"
    table="forum_thread"
>
    <field-descriptor
        name="id"
        column="id"
        jdbc-type="INTEGER"
        primarykey="true"
        autoincrement="true"
        sequence-name="all_sequence"
    >
    </field-descriptor>
    <field-descriptor
        name="version"
        column="version"
        jdbc-type="INTEGER"
        locking="true"
    >
    </field-descriptor>
    
    <field-descriptor
        name="title"
        column="title"
        jdbc-type="VARCHAR"
        length="255"
    >
    </field-descriptor>
    
    <field-descriptor
        name="task_id"
        column="task_id"
        jdbc-type="INTEGER"
    >
    </field-descriptor>
</class-descriptor>
 
***************************** Method to ACCESS DB
***********************************
public java.util.Collection getallTaskbyParentId(Integer id)
      {
            PersistenceBroker broker=null;
            info.oswp.model.Task task=null;
            java.util.Collection c=null;
            try
            {
             broker=getBroker();
             task = new info.oswp.model.Task();
             task.setParenttask_id(id);
             Query q = new QueryByCriteria(task);
             c=broker.getCollectionByQuery(q);
            }
            finally
            {
             if (broker != null)
             {    
                        broker.close();
             }
            }
            log.info("found "+c.size());             
            return c;
      }
 
 
 
 
Roland Vecera