Hi,
    I am using ojb1.0_rc4, ODMG api with OJB queries, mysql4 (innodb tables) in Linux 
Red Hat 7.3 (kernel 2.4.20-20.7).
    I am having a problem using non-decomposed m:n associations. Here is the 
description of my problem: in my business model I have an User class and a Group 
class. User and Group are m:n associated using an indirection table (please, see a 
portion of my repository_user.xml file in the end of this email). So I have the 
following tables: user_1, group_1 and user_group (m:n mapping table). After some 
testing I found out that when I locked User before I locked Group, the database 
(mysql) reported a foreign key violation error. Here's an example:
    
    transaction.begin();
    User u=new User();
    //set user properties
    Group g=new Group();
    //set group properties
    transaction.lock(u,transaction.WRITE);
    transaction.lock(g,transaction.WRITE);
    u.addGroup(g);
    transaction.commit();

    If I lock group before I lock user, there's no problem. After some more 
investigation using p6spy I found out that changing the locking order also changed the 
order of the insert statements executed in the database, hence the foreign key error. 
OJB is inserting a record in user_group (m:n mapping table) before it has inserted the 
user and group records.
    By the way, the user class also has 3 subclasses (teacher, student and 
coordinator). Do you think that using inheritance has anything to do with this problem?
    How can I fix this problem? Is it a bug?

Thanks,
    Jair Jr

Here's a portion of my repository_user.xml file:

<!-- Definitions for com.jma.interescola.core.User -->
<class-descriptor class="com.jma.interescola.core.User" table="user_1">
 
 <field-descriptor id="1" name="_id" column="id" jdbc-type="INTEGER" primarykey="true" 
autoincrement="true"/>
 <field-descriptor id="2" name="_name" column="name" jdbc-type="VARCHAR"/>
 <field-descriptor id="3" name="_email" column="email" jdbc-type="VARCHAR"/>
 <field-descriptor id="4" name="_phone" column="phone" jdbc-type="VARCHAR"/>
 <field-descriptor id="5" name="_password" column="password" jdbc-type="VARCHAR"/>
    
 <collection-descriptor name="_participations" 
element-class-ref="com.jma.interescola.core.Participation" orderby="_exam._start" 
sort="ASC">
  <inverse-foreignkey field-id-ref="2"/>
 </collection-descriptor>
 <collection-descriptor name="_groups" 
element-class-ref="com.jma.interescola.core.Group" indirection-table="user_group" 
orderby="_id" sort="ASC">
  <fk-pointing-to-this-class column="userId"/>
  <fk-pointing-to-element-class column="groupId"/>
 </collection-descriptor> 
 
</class-descriptor>

<!-- Definitions for com.jma.interescola.core.Student -->
<class-descriptor class="com.jma.interescola.core.Student" table="student">

 <field-descriptor id="1" name="_id" column="id" jdbc-type="INTEGER" primarykey="true" 
autoincrement="true"/>
 
 <reference-descriptor auto-delete="true" name="super" 
class-ref="com.jma.interescola.core.User"> 
  <foreignkey field-ref="_id"/>
 </reference-descriptor>

 <!--<collection-descriptor name="_participations" 
element-class-ref="com.jma.interescola.core.Participation" orderby="_exam._start" 
sort="ASC">
  <inverse-foreignkey field-id-ref="2"/>
 </collection-descriptor>-->
</class-descriptor>

<!-- Definitions for com.jma.interescola.core.Teacher -->
<class-descriptor class="com.jma.interescola.core.Teacher" table="teacher">

 <field-descriptor id="1" name="_id" column="id" jdbc-type="INTEGER" primarykey="true" 
autoincrement="true"/>
 
 <reference-descriptor auto-delete="true" name="super" 
class-ref="com.jma.interescola.core.User"> 
  <foreignkey field-ref="_id"/>
 </reference-descriptor>
</class-descriptor>

<class-descriptor class="com.jma.interescola.core.Coordinator" table="coordinator">

 <field-descriptor id="1" name="_id" column="id" jdbc-type="INTEGER" primarykey="true" 
autoincrement="true"/>
 
 <reference-descriptor auto-delete="true" name="super" 
class-ref="com.jma.interescola.core.User"> 
  <foreignkey field-ref="_id"/>
 </reference-descriptor>
</class-descriptor>
   
<!-- Definitions for com.jma.interescola.core.Group -->
<class-descriptor class="com.jma.interescola.core.Group" table="group_1">
 
 <field-descriptor id="1" name="_id" column="id" jdbc-type="INTEGER" primarykey="true" 
autoincrement="true"/>
 <field-descriptor id="2" name="_schoolId" column="schoolId" jdbc-type="INTEGER"/>
 <field-descriptor id="3" name="_name" column="name" jdbc-type="VARCHAR"/>
 <field-descriptor id="4" name="_year" column="year" jdbc-type="INTEGER"/>
 
 <reference-descriptor name="_school" class-ref="com.jma.interescola.core.School">
  <foreignkey field-id-ref="2"/>
 </reference-descriptor>
</class-descriptor>


Reply via email to