Hello,
 
I'm having a problem using ODMG to add a Video and its contained Vector
of VideoData objects to a MySQL database.  The problem is that the first
VideoData object gets written immediately after I commit the
transaction.  The other VideoData objects, however, don't materialize in
the database until after I somehow try to access the previous VideoData
object.
 
Here's the corresponding entries in repository_user.xml (I've deleted
non-relevant fields):
 
<class-descriptor class="com.jsite.multimedia.businessobjects.Video"
table="video">
 
<field-descriptor
 
name="id"
 
column="ID"
 
jdbc-type="INTEGER"
 
primarykey="true"
 
autoincrement="true"
                                                            />
 
<collection-descriptor
 
name="videoDataGroup"
 
element-class-ref="com.jsite.multimedia.businessobjects.VideoData"
 
auto-delete="true"
                                                            >
 
<inverse-foreignkey field-ref="videoId"/>
 
</collection-descriptor>
            </class-descriptor>
            <class-descriptor
class="com.jsite.multimedia.businessobjects.VideoData"
table="video_data">
                                                <field-descriptor
                                                             name="id"
                                                             column="ID"
 
jdbc-type="INTEGER"
 
primarykey="true"
 
autoincrement="true"
                                                />
                                                <field-descriptor
 
name="videoId"
 
column="VIDEO_ID"
 
jdbc-type="INTEGER"
                                                />
                                                <reference-descriptor
                                                            name="video"
 
class-ref="com.jsite.multimedia.businessobjects.Video"
 
auto-retrieve="true"
 
auto-update="true"
                                                >
                                                            <foreignkey
field-ref="videoId"/>
                                    </reference-descriptor>
            </class-descriptor> 
 
And here are the relevant portions of the classes in question:
 
public class Video {
 
      private int       id;
      private Vector    videoDataGroup;
 
public Video() {
      super();
      videoDataGroup = new Vector();
}
      public Collection getVideoDataGroup() {
            return videoDataGroup;
      }
      public void setVideoDataGroup(Vector vector) {
            videoDataGroup = vector;
      }
 
      // .
}
 
public class VideoData {
 
      private int             id;
      private int             videoId;
      private Video           video;
 
public void setVideo(Video video) {
            this.video = video;
      }
 
      // .
}
 
Here's a code snippet that creates the Video object:
 
Video video = new Video();
      
// initialize video's fields here.
      
Vector videoDataGroup = new Vector();
      
for (int i = 0; i < Video.NUM_VIDEO_DATA; i++) {
VideoData videoData = getVideoData(i);
      videoData.setVideo(video);
      videoDataGroup.addElement(videoData);
}
      
video.setVideoDataGroup(videoDataGroup);
VideoManager.addVideo(video);
 
And here's VideoManager.addVideo(), which does the actual adding to the
database:
 
public static void addVideo(Video video) 
{
      try {
            Transaction tx = DatabaseManager.getOdmg().newTransaction();
            
            tx.begin();
            tx.lock(video, Transaction.WRITE);
            tx.commit();
      } 
      catch(LockNotGrantedException e) {
            // code to handle this.
      }
}
 
 
Upon tx.commit(), there will be a new row in the VIDEO table and
(assuming I've added 3 VideoData objects), only one row in VIDEO_DATA
referencing the new VIDEO row.  When I read the VIDEO_DATA row that's in
the database (say the quicktime version of my video), the second
VIDEO_DATA row I originally tried to add to the database materializes.
The minute I try reading that row from the database, the third
VIDEO_DATA row materializes.
 
What am I doing wrong?
 
Here's my jdbc-connection-descriptor
 
<jdbc-connection-descriptor
                     jcd-alias="default"
                     default-connection="true"
                         platform="MySQL"
                         jdbc-level="2.0"
                         driver="com.mysql.jdbc.Driver"
                         protocol="jdbc"
                         subprotocol="mysql"
                         dbalias="//localhost:3306/jsite_db"
                         username="myusername"
                         password="mypassword"
                         eager-release="false"
                         batch-mode="false"
                         useAutoCommit="1"
                         ignoreAutoCommitExceptions="false">
                     
                     <connection-pool maxActive="21" validationQuery=""
/>
            
                        <sequence-manager
className="org.apache.ojb.broker.util.sequence.SequenceManagerMySQLImpl"
>
                                    <attribute attribute-name="grabSize"
attribute-value="20"/>
                                    <attribute
attribute-name="autoNaming" attribute-value="true"/>
                                    <attribute
attribute-name="globalSequenceId" attribute-value="false"/>
                                    <attribute
attribute-name="globalSequenceStart" attribute-value="10000"/>
                        </sequence-manager>
            </jdbc-connection-descriptor >
 
Any help will be much appreciated.
 
-Ara-

Reply via email to