-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 posts ] 
Author Message
 Post subject: UPDATE operations made by Hibernate for a loadAll() method
PostPosted: Wed Sep 03, 2008 9:53 am 
Newbie

Joined: Wed Feb 06, 2008 10:06 am
Posts: 14
Hi there,

I have a problem with Hibernate.

I have a method loadAll() that allows me to retrieve all my RegularityForm entities.
But everytime i use it, i end up with hundreds or thousands of such Hibernate operations (i enabled HQL logs in that case)
Code:
Hibernate: update REGULARITY_FORM set NUMBER=?, CREATION_DATE=?, COMPLEMENTARY_INFORMATION=?, CUSTOMER_SERVICE_INFORMATION=?, STATUS=?, LAST_VALIDATION_DATE=?, EFFECTIVE_TRANCHE_FK=? where ID=?



I use it this way in a regular DAO implementation
Code:
List<RegularityForm> allForms = new ArrayList<RegularityForm>(this.getRegularityFormDao().loadAll());


My loadAll is automatically generated by AndroMDA... so that i dont have anything to do (and it works fine for all other entities).`

Does this problem remind u anything??

Nicolas.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 03, 2008 2:32 pm 
Beginner
Beginner

Joined: Fri Aug 05, 2005 3:36 am
Posts: 28
loadAll() should be retrieving objects from the database, right? With SQL SELECTs? Why is it doing SQL UPDATEs?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 03, 2008 2:44 pm 
Newbie

Joined: Wed Feb 06, 2008 10:06 am
Posts: 14
Indeed, loadAll() should be retrieving objects from the db! With SQL select, one i guess.
BUT i end up with UPDATEs...

This is my question! Why? ;-)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 03, 2008 6:39 pm 
Beginner
Beginner

Joined: Fri Aug 05, 2005 3:36 am
Posts: 28
Well, you could post the code of the loadAll() method; that might help.

However, maybe you are seeing a flush caused by uncommitted and unflushed changes that you've made in the current transaction. When you have flush mode = AUTO, you are likely to see uncommitted changes sent to the database when you perform a subsequent query or other Hibernate operation in the same transaction (and presumably loadAll() is performing a Hibernate operation).

See Chapter 10 section 10 in the Hibernate docs for more.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 04, 2008 2:16 am 
Newbie

Joined: Wed Feb 06, 2008 10:06 am
Posts: 14
First, thanks for your help.

Here is the different pieces of code you might need
(My DAO extends HibernateDAOSupport in springframework, thats why getHibernateTemplate() is used)

Code:
/**
     * @see com.thalys.opalys.domain.RegularityFormDao#loadAll()
     */
    @SuppressWarnings({"unchecked"})
    public java.util.Collection<com.thalys.opalys.domain.RegularityForm> loadAll()
    {
        return this.loadAll(TRANSFORM_NONE);
    }

Code:
    /**
     * @see com.thalys.opalys.domain.RegularityFormDao#loadAll(int)
     */
    public java.util.Collection loadAll(final int transform)
    {
        final java.util.Collection results = this.getHibernateTemplate().loadAll(com.thalys.opalys.domain.RegularityFormImpl.class);
        this.transformEntities(transform, results);
        return results;
    }



Code:
/**
     * Transforms a collection of entities using the
     * {@link #transformEntity(int,com.thalys.opalys.domain.RegularityForm)}
     * method. This method does not instantiate a new collection.
     * <p/>
     * This method is to be used internally only.
     *
     * @param transform one of the constants declared in <code>com.thalys.opalys.domain.RegularityFormDao</code>
     * @param entities the collection of entities to transform
     * @see #transformEntity(int,com.thalys.opalys.domain.RegularityForm)
     */
    protected void transformEntities(final int transform, final java.util.Collection entities)
    {
        switch (transform)
        {
            case TRANSFORM_REGULARITYFORMDETAIL :
                toRegularityFormDetailCollection(entities);
                break;
            case TRANSFORM_REGULARITYFORMLISTITEM :
                toRegularityFormListItemCollection(entities);
                break;
            case TRANSFORM_NONE : // fall-through
                default:
                // do nothing;
        }
    }


I really saw those UPDATE on loadAll... and yet, can there be any flush of uncommited changes made at this moment??

I'll have a look at chatper 10 section 10


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 04, 2008 5:37 am 
Newbie

Joined: Wed Feb 06, 2008 10:06 am
Posts: 14
Quote:
However, maybe you are seeing a flush caused by uncommitted and unflushed changes that you've made in the current transaction. When you have flush mode = AUTO, you are likely to see uncommitted changes sent to the database when you perform a subsequent query or other Hibernate operation in the same transaction (and presumably loadAll() is performing a Hibernate operation).


Well, as a matter of fact, when i do the first iteration using this loadAll() operation, i have no UPDATE operations.
BVut when i do the second and next iterations, i get those UPDATEs...

In my first iteration, i create ONE element of RegularityForm (using create methods provided by my DAO) and i do a setSomething() on it. Would it be the reason? But then i don't understand why i get so many UPDATES (more than 3000)

Nico.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 04, 2008 9:17 pm 
Beginner
Beginner

Joined: Fri Aug 05, 2005 3:36 am
Posts: 28
I'd guess that there is one UPDATE for each RegularityForm that you load from loadAll(). Is it possible that toRegularityFormListItemCollection(..) and/or the other method are modifying the RegularityForms, and then running another query that could cause the flush?

Another question:

How are you demarcating your Hibernate sessions and transactions?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.