Hibernate 4 has performance issues after migration
Our project was moved from JSF1.1 / Hibernate3x to JSF2.1.7 / Hibernate4, performances were added along with it. After selecting the list / entries from the database, it took 30 seconds to migrate, but now it takes 3 to 4 minutes after migration. This is one of the most important problems.
The table I am trying to get has 101 columns and has 11000 records. We are using SQL Server 2008 for the database
Eclipse Kepler development environment
Please help me!
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 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;
}
Tried even with
query.scroll instead of query.list , but the problem remains the same.
I have mentioned and tried all the links below but nothing solved my problem
Migrating from Hibernate 3 to 4 slows down startup
Why is Hibernate query.list () slower?
A simple hibernate request comes back very slowly
I could see some hints with the .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>
source to share
After changing the lazy design, it shrank by almost 1 minute. Changed from lazy = false to lazy = true
<set cascade="delete" inverse="true" lazy="true" name="tblTrackLocationrelations" sort="unsorted" table="tbl_track_locationrelations"> <key column="track_LocationRelations_location_id_fk" /> <one-to-many class="com.src.hibernate.TblTrackLocationrelations" /> </set>
In addition to this, there were several codes that continued to be called through the constructor, so cleaning up the code will help get rid of the performance issue.
source to share