Our project has been migrated from JSF1.1/Hibernate3x to JSF2.1.7/Hibernate4, added primefaces along with it. While fetching the list/records from database it was taking 30 seconds before migration, but now its taking around 3 to 4 mins after migration.It is one of the critical issue.
The table which i am trying to fetch has 101 columns and it has 11000 records. We are using SQL Server 2008 for database
Development Environment is Eclipse Kepler
Please help me out !!
hibernate.cfg.xml
<hibernate-configuration>
<session-factory>
<property name="dialect">
org.hibernate.dialect.SQLServerDialect
</property>
<property name="myeclipse.connection.profile">
com.microsoft.sqlserver.jdbc.SQLServerDriver
</property>
<property name="connection.driver_class">
com.microsoft.sqlserver.jdbc.SQLServerDriver
</property>
<property name="hibernate.show_sql">false</property>
<property name="connection.autocommit">false</property>
<!-- Enable Hibernate's automatic session context management -->
<property name="current_session_context_class">thread</property>
<!-- connection pooling properties -->
<property name="hibernate.c3p0.max_size">20</property>
<property name="hibernate.c3p0.min_size">3</property>
<property name="hibernate.c3p0.timeout">100</property>
<property name="hibernate.c3p0.max_statement">50</property>
<property name="hibernate.c3p0.idle_test_period">300</property>
<property name="hibernate.c3p0.acquire_increment">3</property>
<property name="transaction.factory_class">
org.hibernate.transaction.JDBCTransactionFactory
</property>
<!-- For Hibernate caching -->
<property name="hibernate.cache.use_query_cache">true</property>
<property name="hibernate.cache.use_second_level_cache">true</property>
<property name="hibernate.cache.region.factory_class">org.hibernate.cache.ehcache.EhCacheRegionFactory</property>
<property name="hibernate.cache.provider_class">org.hibernate.cache.ehcache.EhCacheProvider</property>
<property
name="hibernate.cache.provider_configuration_file_resource_path">
com/src/hibernate/ehcache.xml
</property>
</session-factory>
Implementation
public List search(){
Transaction tr=null;
session=HibernateSessionFactory.getSession();
StringBuilder qry = new StringBuilder();
List list=new ArrayList();
try{
tr=session.beginTransaction();
qry.append("select locn,(select locationTypeName from TblLocationTypes where locationTypeIdPk = "
+ " locn.trackLocationInfoLocationTypeIdFk) as locType,"
+ "(select locationDivisionName from TblLocationDivision "
+ "where locationDivisionIdPk=locn.trackLocationInfoDivision) as divis "
+ "from TblTrackLocationinformation locn where 1=1 ");
Query query = session.createQuery(qry.toString());
list = query.list();
tr.commit();
}
catch(Exception e){
if(tr != null){
tr.rollback();
}
e.printStackTrace();
}finally{
session.flush();
session.clear();
session.clear();
}
return list;
}
Have tried even with
query.scroll instead of query.list but issue remains same.
I have referred and tried all the below links but nothing solved my issue
Migration from Hibernate 3 to 4 slows down startup
Why is the Hibernate query.list() slow?
Simple hibernate query returning very slowly
I could see some hints with .hbm.xml file
.hbm.xml
<set cascade="delete" inverse="true" lazy="false" name="tblTrackLocationrelations" sort="unsorted" table="tbl_track_locationrelations"> <key column="track_LocationRelations_location_id_fk" /> <one-to-many class="com.src.hibernate.TblTrackLocationrelations" /> </set>