db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Antony S. Kraievoy" <archv...@ukr.net>
Subject Re: AW: Issue with HSQLDB manager
Date Mon, 09 Dec 2002 10:20:19 GMT
Hi again

Mahler Thomas wrote:

> Please post your actual code.
> I cannot make out what happened from the SQL statements...


> What i did:
> OJB was running against hsqldb, i've just (in previous build) defined new class-descriptor
for a table,
> wrote new class itself. And wrote simple code snippet that gets extent for new class
and uses it to render
> it in html.
> Table was empty -- all was ok. I viewed pretty and empty table.
> Then, i started up hsqldb manager and inserted new record to this table. :)))).
> Just because i was lazy and wanted to view presentation without writing some forms for
creation of new records.
> Then i concecutively tried to view html presentation of this record.
> 
> What happened every time i tried to view this table:
> 1. My code tried to get extent.
> 2. OJB tried to WRITE this record once more time to DB! (this was totally unexpected)
> <thise steps below are specific to my app>
> 3. and HSQLDB didn't allow it because of unique constraint on one field (it will be duplicated
otherwise) (this is MY trouble).
> 4. OJB rolled back transaction in which i tried to get extent.
> 5. My code caught exception, but presentation logic crashed at next step (this is surely
MY trouble)
> because code got null instead of empty collection.
> 
> OJB considers that newly created out of app record must be WRITTEN to db once more...
> Or it was assumed that db will be modified only by OJB?


this was in JSP:
<%
   Collection dimensions = Products.findAllDimensions();
   ....
%>


this method was used directly in JSP:

public class Products {
   public static Collection findAllDimensions () {
     return OJB_ODMG_DAO.findAll(ProductDimension.class);
   }
}

and these excerpts of OJB_ODMG_DAO were used by class Products:

public class OJB_ODMG_DAO {
   private static Implementation ODMGImpl = null;
   static {
     //	init ODMGImpl
     System.setProperty("OJB.properties","com/archvile/ooo/ojb/OJB.properties");
     ODMGImpl = OJB.getInstance();
     Database db = ODMGImpl.newDatabase();
     try {
       db.open("com/archvile/ooo/ojb/repository.xml",Database.OPEN_READ_WRITE);
     } catch (ODMGException ex) {
       ex.printStackTrace();
     }
   }
   /**Gets collection of all persistent objects for specified class.
    * @param adaptee <code>Class</code> of objects to be loaded.
    * @return <code>Collection</code> of all objects of this class.*/
   public static Collection findAll(Class adaptee) {
     Transaction transaction = null;
     Collection extent = null;
     try {
       transaction = ODMGImpl.newTransaction();
       transaction.begin();
       OQLQuery query = ODMGImpl.newOQLQuery();
       query.create("select extent from "+adaptee.getName());
       extent = (DList) query.execute();
       transaction.commit(); // here strange thing happened
     } catch (Throwable t) {
       if (transaction.isOpen()) transaction.abort();
       System.out.println("[devel:ojb-odmg-dao] Getting extent failed. \r\n\tRoot cause:"+t.getMessage());
       return null;
     }
     return extent;
   }
}




Mime
View raw message