Hi,
> Hi,
> 
> I have looked through the OJB junit source code for the odmg and broker
> test cases, and I still can't get this to work.  If anyone cares to take
> a look at the following code and suggest what I'm doing wrong, I'd be
> indebted to you...
> 
> Searches in the list archive are not very fruitful using the error
> messages I'm getting like...
> [org.apache.ojb.odmg.TransactionImpl] INFO: Abort transaction was called
> on tx [EMAIL PROTECTED], associated PB was
> [EMAIL PROTECTED]
> org.odmg.LockNotGrantedException: Can not lock
> [EMAIL PROTECTED] for WRITE
> 
> 
> Here is java code for simple test case:
> 
> //note I dropped all the import statements for brevity
> public class ClassM implements Serializable {
>       protected int id;
>       protected Collection mton;
> 
>       public void setId(int in) {
>       this.id = in;
>       }
> 
>       public int getId() {
>       return id;
>       }
> 
>       public void setMton(Collection in) {
>       this.mton = in;
>       }
> 
>       public Collection getMton() {
>       return mton;
>       }
> }
> 
> 
> public class ClassN implements Serializable {
>       protected int id;
>       protected Collection mton;
> 
>       public void setId(int in) {
>       this.id = in;
>       }
> 
>       public int getId() {
>       return id;
>       }
> 
>       public void setMton(Collection in) {
>       this.mton = in;
>       }
> 
>       public Collection getMton() {
>       return mton;
>       }
> }
> 
> 
> public class ClassMtoN implements Serializable {
> 
>       protected int m_id;
>       protected int n_id;
>       protected ClassM m;
>       protected ClassN n;
>       protected String description;
> 
>       public void setM_id(int in) {
>       this.m_id = in;
>       }
> 
>       public int getM_id() {
>       return m_id;
>       }
> 
>       public void setN_id(int in) {
>       this.n_id = in;
>       }
> 
>       public int getN_id() {
>       return n_id;
>       }
> 
>       public void setM(ClassM in) {
>       this.m = in;
>       }
> 
>       public ClassM getM() {
>       return m;
>       }
> 
>       public void setN(ClassN in) {
>       this.n = in;
>       }
> 
>       public ClassN getN() {
>       return n;
>       }
> 
>       public void setDescription(String in) {
>       this.description = in;
>       }
> 
>       public String getDescription() {
>       return description;
>       }
> }
> 
> 
> 
> public class TestingMtoN  {
> 
>     Implementation odmg = null;
>     Database db = null;
> 
>     protected boolean test;
>     protected String queryString;
> 
>     public void setQueryString(String s) {
>       queryString = s;
>     }
> 
> 
>     //I just have this setTest method so that I can use this in a bean
>     //and test via jsp page.
>     public void setTest(boolean b)  {
>       // get odmg facade instance
>       odmg = OJB.getInstance();
>       db = odmg.newDatabase();
>       //open database
>       try{
> //this is not the problem :)
>           db.open(IConstants.REPOSITORY_KEY, Database.OPEN_READ_WRITE);
> 
>           // Start a transaction
>           Transaction tx = null;
> 
>           
> 
>           
>           ClassM m = new ClassM();
>           try {
>               tx = odmg.newTransaction();
>               tx.begin();
>               tx.lock(m,Transaction.WRITE);
>               tx.commit();
>           }catch( Exception ex ){
>               // Rollback the transaction
>               tx.abort();
>               throw ex;
>           }
> 
> 
> 
>           ClassN n = new ClassN();
>           try {
>               tx = odmg.newTransaction();
>               tx.begin();
>               tx.lock(n,Transaction.WRITE);           
>               tx.commit();
>           }catch( Exception ex ){
>               // Rollback the transaction
>               tx.abort();
>               throw ex;
>           }
> 
> 
> 
>           ClassMtoN mton = new ClassMtoN();
> 
>           try {
>               tx = odmg.newTransaction();
>               tx.begin();
>               tx.lock(mton,Transaction.WRITE);
>               mton.setM(m);
>               mton.setN(n);
> 
>               tx.commit();
>           }catch( Exception ex ){
>               // Rollback the transaction
>               tx.abort();
>               throw ex;
>           }
>           
>       }catch( Exception ex ){
>           StringWriter s = new StringWriter();
>           ex.printStackTrace(new PrintWriter(s));
>           System.out.println(s.toString());
>       } finally {
>           try {
>               db.close();
>           } catch (Exception ignored) {
>               //do nothing
>           }
>       }
>     }
> }
> 
> 
> Here is from repository_user.xml:
> 
>   <class-descriptor
>         class="com.worldcycling.web.quickfill.ClassM"
>         table="class_m"
>   >
> 
>       <field-descriptor
>          name="id"
>          column="id"
>          jdbc-type="INTEGER"
>          primarykey="true"
>          autoincrement="true"
>       />
>       <collection-descriptor
>          name="mton"
>          element-class-ref="com.worldcycling.web.quickfill.ClassMtoN"
>       >
> <inverse-foreignkey field-ref="m_id" />
> </collection-descriptor>
> 
>   </class-descriptor>
> 
>   <class-descriptor
>         class="com.worldcycling.web.quickfill.ClassN"
>         table="class_n"
>   >
> 
>       <field-descriptor
>          name="id"
>          column="id"
>          jdbc-type="INTEGER"
>          primarykey="true"
>          autoincrement="true"
>       />
> 
>       <collection-descriptor
>          name="mton"
>          element-class-ref="com.worldcycling.web.quickfill.ClassMtoN"
>       >
> <inverse-foreignkey field-ref="n_id" />
> </collection-descriptor>
> 
> 
> 
>   </class-descriptor>
> 
>   <class-descriptor
>         class="com.worldcycling.web.quickfill.ClassMtoN"
>         table="class_mton"
>   >
> 
>       <field-descriptor
>          name="m_id"
>          column="m_id"
>          jdbc-type="INTEGER"
>          primarykey="true"
>          locking="true"
>       />
>       <field-descriptor
>          name="n_id"
>          column="n_id"
>          jdbc-type="INTEGER"
>          primarykey="true"
>          locking="true"
>       />
>       <field-descriptor
>          name="description"
>          column="description"
>          jdbc-type="varchar"
>       />
> 
>       <reference-descriptor
>          name="m"
>          class-ref="com.worldcycling.web.quickfill.ClassM"
>       >
>          <foreignkey field-ref="m_id" />
>       </reference-descriptor>
>       <reference-descriptor
>          name="n"
>          class-ref="com.worldcycling.web.quickfill.ClassN"
>       >
>          <foreignkey field-ref="n_id" />
>       </reference-descriptor>
> 
> 
>   </class-descriptor>
> 
> 
> and here is the sql:
> 
> create table class_m (
> id integer);
> 
> create table class_n (
> id integer);
> 
> create table class_mton (
> m_id integer,
> n_id integer,
> description text
> );


Incidentally, when I try the test listed in java code above, the insert
seems to work one time, but then fails on subsequent attempts with:
org.odmg.LockNotGrantedException: Can not lock [EMAIL PROTECTED] for WRITE

Thanks,
Steve


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to