Hi Armin,

thanks for help.

Just to be sure that I got the point: When there is a 'proxy="dynamic"' in the class-descriptor, proxies are always used when more than one object is queried?

I thought that proxies are only used when retrieving a collection through a relation (1:n or m:n, e.g. ShoppingCart.getArticles() - see below)...

Regards,

Abid

Armin Waibel schrieb:
Hi Abid,

Abid Hussain wrote:
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???


You are using dynamic proxies for all Account_2 objects:

<class-descriptor class="modulverwaltung.beans.Account_2"
    table="ACCOUNT_2" proxy="dynamic">

The query result collection isn't a proxy object. Instead each result object is a proxy object of persistence capable object (Account_2 object). In most cases this doesn't have an performance advantage.

If you now store each of these objects without materialization (e.g. your log.debug() force the materialization of the object) OJB thinks that the object didn't change and skip the update.

regards,
Armin


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>



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



--

Abid Hussain
Mail: [EMAIL PROTECTED]
Web: http://www.abid76.de

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

Reply via email to