-->
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.  [ 8 posts ] 
Author Message
 Post subject: HUGE optimization issues with Hibernate
PostPosted: Mon Jul 16, 2007 11:17 am 
Newbie

Joined: Mon Jul 16, 2007 11:02 am
Posts: 4
I was passed off a java project at my company that is structured with hibernate and struts. The entire downfall of this project seems to revolve around hibernate, and the amount of overhead it is causing.

I checked the query logs for the database, and I am seeing upwards of 6500, yes SIX THOUSAND FIVE HUNDRED, queries being executed just on a login procedure. You would think only ONE query would be needed.

Essentially, the software is a web based application for a study going on at a hospital, and is basically a patient enrolment tool, as well as a tracking tool for a patient's daily progress. Each user is assigned to an ICU (Intensive care unit) in which they can enrol patients under. The database access is basically linked as follows:

User account > ICU > patients under ICU > daily data entered for the patient each day

I have tried to use lazy loading to kind of isolate each section to cut down on the amount of database requests, but it only help marginally, and as the database is growing in size as more patients are enroled, it gets even slower.

Does anyone have any general tips for hibernate optimization. Clients are getting upset, and I really need to come up with a solution soon.

It really seems hibernate is more of a burden then it helps, but unfortunately, the application is so heavily structured on it, that it would not be feasible to convert it to the very easy to use JDBC to result set standard DB access.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 16, 2007 12:28 pm 
Newbie

Joined: Mon Jul 16, 2007 11:02 am
Posts: 4
Lots of views, no replies...

ANY help would be appreciated. If you need more elaboration on anything, please let me know.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 16, 2007 12:58 pm 
Newbie

Joined: Thu Mar 29, 2007 3:16 pm
Posts: 7
Location: Brasil
Are you using connection pooling and/or object/query cache?

Post here your hibernate.cfg.xml and the table mappings used on the user login.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 16, 2007 2:00 pm 
Newbie

Joined: Mon Jul 16, 2007 11:02 am
Posts: 4
lucashungaro wrote:
Are you using connection pooling and/or object/query cache?

Post here your hibernate.cfg.xml and the table mappings used on the user login.


My hibernateconfig file is over 1,200 lines. Is there any portion you would specifically want to see?

Edit: Sorry, I thought you meant my hibernate mappings. Here is hibernate.cfg.xml.


<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<!-- Generated by MyEclipse Hibernate Tools. -->
<hibernate-configuration>

<session-factory>
<property name="hibernate.cglib.use_reflection_optimizer">false</property>
<property name="connection.datasource">java:comp/env/jdbc/ABATE</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="show_sql">false</property>
<!-- <property name="hibernate.transaction.factory_class">org.hibernate.transaction.JTATransactionFactory</property>-->
<mapping resource="hibernate_mappings.xml" />
</session-factory>

</hibernate-configuration>


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 16, 2007 2:09 pm 
Newbie

Joined: Mon Jul 16, 2007 11:02 am
Posts: 4
And my user object mappings

Code:
<class name="com.cissec.objects.user.SurveyUser" table="surveyuser">
      <id name="id" column="UID" type="integer">
         <generator class="native"/>
      </id>
      <property name="userName" column="UName" type="text"/>
      <property name="firstName" column="FirstName" type="text"/>
      <property name="lastName" column="LastName" type="text"/>
      <property name="password" column="Password" type="text"/>
      <property name="email" column="EMail" type="text"/>
      <property name="permissionLevel" column="Permission" type="integer"/>
      <set name="permissions" table="user_permission" lazy="false">
           <key column="UID"/>
           <many-to-many class="com.cissec.objects.icu.ICU" column="ICUID" />          
       </set>      
       <many-to-one name="addr" column="Addr" lazy="false" cascade="save-update"/>
       <property name="phoneNum" column="PhoneNumber" type="text"/>
       <property name="faxNum" column="FaxNumber" type="text"/>
      
       <property name="gender" column="Gender" type="text"/>      

       <property name="refDetails" column="RefDetails" type="text"/>
       <property name="otherRef" column="RefOther" type="text"/>
       <property name="otherICURole" column="RoleOther" type="text"/>      
       <property name="ethicsRequired" column="EthRequired" type="integer"/>     
   </class>


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 16, 2007 4:07 pm 
Newbie

Joined: Thu Mar 29, 2007 3:16 pm
Posts: 7
Location: Brasil
I think you could set lazy="true" for the sets you don't need to use at the login process.

Are you getting 6500 different queries or the same queries are appearing in multiples?


Top
 Profile  
 
 Post subject: n+1 selects issue may be?
PostPosted: Mon Jul 16, 2007 5:46 pm 
Newbie

Joined: Thu Jul 12, 2007 5:33 pm
Posts: 5
Hi ,
You might have already done this..but did you see if this is n+1 select issue? are your 6500 selects going against the same set of tables?

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 17, 2007 9:19 am 
Newbie

Joined: Fri Aug 04, 2006 6:09 am
Posts: 18
To continue the point above about n+1 selects:

It may be due to excessive object navigation. Are their any FOR loops over domain objects?

For example, I came across some code recently that was iterating over all the Company domain objects and then for each one checking if it had a valid licence. This is so wasteful as it will also include companies no longer valid. Each company also has an Address component that will always be loaded (i dont think that can be turned off).

The classic n+1 selects problem.

The solution was to write some HQL that just got back the valid companies. I suspect there is ALOT of code out there like this.

R


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 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.