db-ojb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christoph Hermann <christoph.herm...@tu-clausthal.de>
Subject Decomposed m:n mapping with ojb and jdo
Date Fri, 28 Jan 2005 13:49:57 GMT
Hello,

i try to realize an m:n mapping using ojb/jdo and update the java 
classes with cocoon using cforms.

My problem ist, that i don't get the intermediate table to update 
correctly in the database.

I have the following three classes:

public class Profile implements Serializable {
    private int id;
    private String name;
    private Collection menuCategories = new ArrayList();
    private Collection profileMenuCategories = new ArrayList();
...
}

public class ProfileMenuCategory implements Serializable {
    private int category_id;
    private int profile_id;
    private int sortNr;
    private Profile profile = new Profile();
    private MenuCategory category = new MenuCategory();
...
}

public class MenuCategory implements Serializable {
    private int id;
    private String name;
    private Collection profiles = new ArrayList();
    private Collection profileMenuCategories = new ArrayList();
...
}

and the following Database-Schema (postgreql):

CREATE TABLE profiles (
 id INT8 DEFAULT nextval('profiles_id_seq'::text) NOT NULL,
 name VARCHAR(255) NOT NULL,
 CONSTRAINT profiles_id_pkey PRIMARY KEY(id),
 CONSTRAINT profiles_name_ukey UNIQUE(name)
);

CREATE TABLE menu_categories (
 id INT8 DEFAULT nextval('menu_categories_id_seq'::text) NOT NULL,
 name VARCHAR(255) NOT NULL,
 CONSTRAINT menu_categories_id_pkey PRIMARY KEY(id),
 CONSTRAINT menu_categories_name_ukey UNIQUE(name)
);

CREATE TABLE rel_profiles_menu_categories (
 profiles_id INT8 NOT NULL REFERENCES profiles(id),
 menu_categories_id INT8 NOT NULL REFERENCES menu_categories(id),
 sort_nr INT8 DEFAULT 0 NOT NULL,
 CONSTRAINT rel_profiles_menu_categories_pkey PRIMARY 
KEY(profiles_id,menu_categories_id)
);

My repository.xml looks like this:
 <!-- Profile -->
 <class-descriptor class="papillon.Profile" table="profiles">
  <field-descriptor name="id" primarykey="true" nullable="false" 
default-fetch="true" autoincrement="true" column="id" 
sequence-name="profiles_id_seq" jdbc-type="INTEGER" />
  <field-descriptor name="name" nullable="false" default-fetch="true" 
column="name" jdbc-type="VARCHAR" />
  <collection-descriptor 
   name="profileMenuCategories" 
   element-class-ref="papillon.ProfileMenuCategory" 
   otm-dependent="false"
   auto-retrieve="true"
   auto-update="false"
   auto-delete="false"
   orderby="sortNr" 
   sort="ASC"
   >
          <inverse-foreignkey field-ref="profile_id" />
  </collection-descriptor>
  <collection-descriptor 
   name="menuCategories" 
   element-class-ref="papillon.MenuCategory" 
   auto-retrieve="true" 
   auto-update="link" 
   auto-delete="link" 
   indirection-table="rel_profiles_menu_categories"
   otm-dependent="false" 
   
collection-class="org.apache.ojb.broker.util.collections.ManageableArrayList"
   orderby="sort_nr" 
   sort="ASC"
   >
          <fk-pointing-to-this-class column="profiles_id"/>
        <fk-pointing-to-element-class column="menu_categories_id"/>
  </collection-descriptor>
 </class-descriptor>
 
 <!-- Category -->
 <class-descriptor class="papillon.MenuCategory" 
table="menu_categories">
  <field-descriptor name="id" primarykey="true" nullable="false" 
default-fetch="true" autoincrement="true" column="id" 
sequence-name="menu_categories_id_seq" jdbc-type="INTEGER" />
  <field-descriptor name="name" nullable="false" default-fetch="true" 
column="name" jdbc-type="VARCHAR" />
        <collection-descriptor
   name="profileMenuCategories" 
   element-class-ref="papillon.ProfileMenuCategory"
   orderby="sortNr" 
   sort="ASC"
   auto-retrieve="true"
   auto-update="false"
   auto-delete="false"
   otm-dependent="false" 
   >
           <inverse-foreignkey field-ref="category_id" />
  </collection-descriptor>
  <collection-descriptor 
   name="profiles" 
   element-class-ref="papillon.Profile" 
   auto-retrieve="true" 
   auto-update="link" 
   auto-delete="link" 
   indirection-table="rel_profiles_menu_categories"
   otm-dependent="false" 
   
collection-class="org.apache.ojb.broker.util.collections.ManageableArrayList"
   orderby="sort_nr" 
   sort="ASC"
   >
          <fk-pointing-to-this-class column="menu_categories_id"/>
        <fk-pointing-to-element-class column="profiles_id"/>
  </collection-descriptor>
 </class-descriptor>
 
 <!-- ProfileMenuCategory -->
 <class-descriptor class="papillon.ProfileMenuCategory" 
table="rel_profiles_menu_categories">
  <field-descriptor name="profile_id" column="profiles_id" 
jdbc-type="INTEGER" primarykey="true" />
  <field-descriptor name="category_id" column="menu_categories_id" 
jdbc-type="INTEGER" primarykey="true" />
  <field-descriptor name="sortNr" column="sort_nr" 
jdbc-type="INTEGER" />
  <reference-descriptor 
   name="profile" 
   class-ref="papillon.Profile"
   auto-retrieve="true"
   auto-update="false"
   auto-delete="false"
   >
   <foreignkey field-ref="profile_id" />
  </reference-descriptor>
  <reference-descriptor 
   name="category" 
   class-ref="papillon.MenuCategory"
   auto-retrieve="true"
   auto-update="false"
   auto-delete="false"
   >
   <foreignkey field-ref="category_id" />
  </reference-descriptor>
 </class-descriptor>


I tried to vary the auto-xxx settings, but none does give the expected 
results. (No matter what i do, the intermediate table is not updated.)
Is my repository correct or should i change it (if, how?)?
And can anyone tell me wheter i need to use otm-dependent="true" or not 
when using jdo?
The docs just tell me to set auto-update and auto-delete to false when 
using jdo.

Christoph

Mime
View raw message