-->
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.  [ 1 post ] 
Author Message
 Post subject: Hibernate query.list() is slower than HibernateTemplate.find
PostPosted: Fri May 08, 2015 12:56 am 
Newbie

Joined: Tue Mar 17, 2015 4:36 am
Posts: 3
We upgraded our project from Spring 3x/Hibernate 3x to Spring 4.1.5/Hibernate 4.3.8.

Initially we were using HibernateTemplate. During upgrade we removed the HibernateTemplate of spring and used Spring's declarative transaction management.

Earlier our query with hibernateTemplate used to take very sort time to retrieve 3500 records from DB. Now when are using query.list(), the running time is coming in minutes (4-5 mins approx).

Old Code
Code:
DAO Class:
---------
public List<LatestRecVO> getListRecs(String listId) {
    HibernateTemplate ht = new HibernateTemplate(getSessionFactory()); 
    List<LatestRecVO> listOfRecs = ht.find(" from LatestRecVO a where a.listId = ? order by a.listRecId asc", Long.valueOf(listId) );
    return listOfRecs;
}

Service Class:
--------------
@Transactional
public List<LatestRecVO> getListRecs(String listId) {
    List<LatestRecVO> listOfRecs = listDao.getListRecDetails(listId);
    return listOfRecs;
}

New Code
Code:
DAO Class:
---------
public List<LatestRecVO> getListRecs(String listId) {
    Query q = getSession().createQuery(" from LatestRecVO a where a.listId = (:listId) order by a.listRecId asc"); 
    q.setParameter("listId", Long.valueOf(listId));
    List<LatestRecVO> listOfRecs = q.list();
    return listOfRecs;
}

Service Class:
--------------
@Transactional
public List<LatestRecVO> getListRecs(String listId) {
    List<LatestRecVO> listOfRecs = listDao.getListRecDetails(listId);
    return listOfRecs;
}


The entity class LatestRecVO do not have any associated entity with it.

I checked the Hibernate Template's find() method and saw its uses some caching.

Tried 2nd level cache along with Query Cache but still the same result. I may have configured 2nd level cache incorrectly but to try it again i want to be sure that its the way out.

I enabled show_sql and can see it just ran a singly query. On DB the same query takes some milliseconds to run. It seems like hibernate is taking time to build objects from the result.

On one of the post it was mentioned that its mandate to have a default constructor in our entities. I have not created any arg constructor in my entity class so i assume that i do have java's default constructor in place.

Any pointer in this will be really helpful.


Update

Sorry, I cannot post the complete code here, so just giving the details. I have the composite primary key for LatestRecVO. I have created a class LatestRecPK for primary key, it implements serializable and have @Embeddable annotation. In LatestRecVO i have given @IdClass(LatestRecPK.class) to include the primary key class. LatestRecVO has a CLOB property along with String, Long and @Temporal(TemporalType.DATE) properties and corresponding setters/getters.

We ran the same query with plain JDBC, iterated resultset and formed objects in while loop. JDBC too took some 3 minutes for creating all 4k objects and adding them to a list.


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

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.