Re: question about storing objects

Abid Hussain <[email protected]> Fri, 16 May 2008 16:28:40 +0200
Newsgroups gmane.comp.jakarta.ojb.user
Message-ID <[email protected]>
Hi again,

I think this issue has to something with the materialization of objects 
(when using proxies). But I thought that proxies are only used, when 
retrieving a corresponding collection of an object (in 1:n and m:n 
relations, e.g. ShoppingCart.getArticles()...).

What I'm doing when using findAll() (see below) is something like SELECT 
* FROM <tablename>. I thought, in this case no proxies are used???

Regards,

Abid


Abid Hussain schrieb:
> Hi everybody,
> 
> I have written a storeAll()-method in a dao to store all given objects 
> in one transaction (you find the code at the end of this mail).
> 
> Now please have a look at the following lines of code:
> Account_2DAO dao1 = new Account_2DAO("DB1");
> Collection<Account_2> accounts = dao1.findAll(Account_2.class);
> logger.debug(accounts);
> Account_2DAO dao2 = new Account_2DAO("DB2");
> dao2.storeAll(accounts);
> 
> As you see, that there are two daos initialized. The first (dao1) 
> retrieves all objects (using findAll()) from a database (DB1). The 
> second (dao2) stores all retrieved objects into another database (DB2).
> The findAll()-method works fine.
> 
> But the storeAll()-method only works when the line of code
> logger.debug(accounts);
> is called. If not, no data is inserted.
> 
> Any ideas what's going wrong (you find the class-descriptor file below)?
> 
> Regards,
> 
> Abid
> 
> 
> Code of storeAll():
> public void storeAll(Collection<T> valueObjects)
>         throws PersistentStoringException {
> 
>     if (valueObjects != null) {
>         try {
>             broker.beginTransaction();
>             for (T valueObject : valueObjects) {
>                 broker.store(valueObject, ObjectModification.INSERT);
>             }
>             broker.commitTransaction();
>         } catch (Exception e) {
>             broker.abortTransaction();
>             throw new PersistentStoringException(
>                     "Error while storing objects.\n" + e);
>         } finally {
>             if (broker != null && !broker.isClosed())
>                 broker.close();
>         }
>     }
> }
> 
> Class-descriptor of Account_2:
> <class-descriptor class="modulverwaltung.beans.Account_2"
>     table="ACCOUNT_2" proxy="dynamic">
>     <field-descriptor name="id" column="ID" primarykey="true"
>         autoincrement="true" sequence-name="Account_Id_Seq" />
>     <field-descriptor name="username" column="Username"
>         jdbc-type="VARCHAR" />
>     <field-descriptor name="role" column="Rolle" jdbc-type="VARCHAR" />
> </class-descriptor>
> 

-- 

Abid Hussain
Mail: [email protected]
Web: http://www.abid76.de