-->
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: JDBC and Hibernate performance
PostPosted: Mon Jul 06, 2009 2:08 pm 
Newbie

Joined: Mon Jul 06, 2009 12:57 pm
Posts: 1
Hi Gavin, Christian
i am a newbie in hibernate, i am facing performance issue after implementing hibernate. i read your replies for one of the old thread and followed the hql queries that you suggested with improvement in performance but not faster than jdbc. jdbc still seems to be 4-7 times faster than hibernate, i am sure , i have not configured hibernate properly.

i have a table in my db which has 100000 records, i am reading all the records from this table and displaying on our webpage.

MY QUESTION IS :
for the first request the jdbc might outperform hibernate bcos of delay in caching all the results. but on subsequent request for the same methods hibernate should perform faster than jdbc since it has already cached the result ?
buts its not.

Please have a look at my configuration files and the code.
i followed hibernate tutorial in netbeans site http://www.netbeans.org/kb/docs/web/hib ... ebapp.html, and did some changes to enable the second level cache with ehcache provider.

hibernate.cfg.xml :

<hibernate-configuration>
<session-factory>
<property name="cache.provider_class">org.hibernate.cache.EhCacheProvider</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/test</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.show_sql">false</property>
<property name="hibernate.current_session_context_class">thread</property>
<property name="hibernate.cache.use_second_level_cache">true</property>
<mapping resource="com/login/Logintable.hbm.xml"/>
<class-cache class="com.login.Logintable" include="all" usage="read-only"/>
</session-factory>
</hibernate-configuration>

Logintable.hbm.xml :

<hibernate-mapping>
<class name="com.login.Logintable" table="logintable" catalog="test">
<id name="user" type="string">
<column name="user" />
<generator class="assigned" />
</id>
<property name="pass" type="string">
<column name="pass" />
</property>
</class>
</hibernate-mapping>

in Logintable class equals and hashcode methods are overrided appropriately.

helper class has the code
the sql method :
List<String> userList = new ArrayList();
java.sql.Connection conn = linktodata();
Statement s = (Statement) conn.createStatement();
s.executeQuery("SELECT * from logintable");
ResultSet rs = s.getResultSet();
System.out.println("total # of records found by hibernate :");
int count = 0;
while (rs.next()) {
userList.add(rs.getString("user"));
}

the hibernate method :
Query q = session.createQuery ("select new Logintable(t.user) from Logintable t");
records = (List<Logintable>) q.list();

the constructor has
this.session = HibernateUtil.getSessionFactory().getCurrentSession();
org.hibernate.Transaction tx = session.beginTransaction();
session.setCacheMode(CacheMode.GET);

ehcache.xml
<?xml version="1.0" encoding="UTF-8"?>
<ehcache>
<diskStore path="java.io.tmpdir"/>
<defaultCache maxElementsInMemory="100000"
eternal="false"
timeToIdleSeconds="120"
timeToLiveSeconds="120"
overflowToDisk="true"
diskPersistent="false"
diskExpiryThreadIntervalSeconds="120"
memoryStoreEvictionPolicy="LRU" />
<cache name="com.login.Logintable"
maxElementsInMemory="150000"
eternal="true"
overflowToDisk="false"
timeToIdleSeconds="300"
timeToLiveSeconds="600"/>
</ehcache>


My jsp page has helper class instance variable, and helps maintaing just one copy of the helper class and avoids re instantiating of the session for each request.

i would be thankful if you guide me setting the configuration properly or any pointers that might improve my applications performance as per my project requirement will be greatly appreciated.

thanks in advance


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.