-->
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.  [ 5 posts ] 
Author Message
 Post subject: Comprehensional Problems - optimizing query/design
PostPosted: Wed Feb 09, 2005 9:05 am 
Beginner
Beginner

Joined: Tue Jan 11, 2005 5:50 am
Posts: 43
Location: Zurich (Suisse)
Hello

I am having a mapping structure as shown in detail below. There are n services which have n MMSAbos. Each MMSAbo represents the startdate of one content item and the content referer and other data.

What I did sofar was to enable caching, lazy loading and batch statements. With cacheing it seems that after reloading the page (which displays the gatered data) there might be not a greater time gain, but I am not completely sure. At the moment I am using a long session, so the session is stretched over more than one request cycle.

I am using the EhCache and set ehcache.xml.

The execution of the query, as the query which is shown below, takes a "lot" of time.

So my questions are, did I do something wrong with the mappings, eg. is there a flaw in my query/mapping which causes unnecessary read/writes to the cache or db?

As I said, I think that there are no hits on the cache after reloading, the retrieval time is roughly the same, do I have a misconception about the cache, isn't each object retrieved once saved in the cache as configured and fetched from the cache as often as possible?

If I already loaded the services and its maps of MMSAbos, shouuldn't be the graph be loaded into the memory and cache and in my case even into the HTTPSession and stay there for as long as the session is not closed?

Is there another way than to make a join as I did to fetch the abos "just" to have a selection on a property of all mmsAbos?


I hope that someone could help me out on some of my questions. I really had much and fast progress with Hibernate, but now I do not know how to tackle my problem.

Thank your for any help.

Best regards
Tarik


Hibernate version:

2

Mapping documents:

Service Mapping (Parent):
Code:
<class name="com.someCompany.MMSCAdmin.beans.Service" table="SERVICE" lazy="true" batch-size="20" optimistic-lock="all" dynamic-update="true">
      <id name="serviceID" type="long" column="SERVICE_ID">
         <generator class="assigned"/>
      </id>
      <property name="name" type="java.lang.String" column="NAME" not-null="true" length="100"/>
      <property name="serviceTable" type="java.lang.String" column="SERVICETABLE" not-null="true" length="100"/>
      <!-- Associations -->
      <map name="keywords" lazy="true" sort="natural" order-by="KEYWORD">
         <key column="SERVICE_ID"/>
         <index column="KEYWORD" type="string"/>
         <one-to-many class="com.someCompany.MMSCAdmin.beans.Keyword"/>
      </map>
      <map name="abos"  lazy="true" sort="natural" order-by="SENDDATESTART">
         <key column="SERVICE_ID"/>
         <index column="MMSABO_ID" type="int"/>
         <one-to-many class="com.someCompany.MMSCAdmin.beans.MMSAbo"/>
      </map>
   </class>
<query name="com.someCompany.MMSCAdmin.beans.Service.getAllServicesByAboDates"><![CDATA[
         from com.someCompany.MMSCAdmin.beans.Service as service
         inner join fetch service.abos as abo            
         where abo.senddateStart >= :senddateStart
         and abo.senddateEnd <= :senddateEnd   
         ]]></query>



Abo Mapping (Childs):

Code:
<class name="com.someCompany.MMSCAdmin.beans.MMSAbo" table="MMSABO" lazy="true" batch-size="20" >
      <cache usage="read-write"/>
      <id name="mmsaboID" type="long" column="MMSABO_ID">
         <generator class="assigned"/>
      </id>
      <property name="senddateStart" type="java.util.Date" column="SENDDATESTART" length="19"/>
      <property name="senddateEnd" type="java.util.Date" column="SENDDATEEND" length="19"/>
      <property name="serviceID" type="long" column="SERVICE_ID" not-null="true" length="20"/>
      <property name="composedID" type="long" column="COMPOSED_ID" not-null="true" length="20"/>
      <!-- Associations -->
   </class>


Code between sessionFactory.openSession() and session.close():

Service DAO:

/**
* @param abo
* @return @throws
* HibernateException
*/
public static List getAllServicesByAboDates(MMSAbo abo)
throws HibernateException {
Session session = HibernateUtil.currentSession();
Query query = session
.getNamedQuery("com.someCompany.MMSCAdmin.beans.Service.getAllServicesByAboDates");
query.setString("senddateEnd", abo.getSenddateEndAsString());
query.setString("senddateStart", abo.getSenddateStartAsString());
query.setCacheable(true);
return query.list();
}


Name and version of the database you are using:

MySQL 4.0.16

The generated SQL (show_sql=true):


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 09, 2005 9:10 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
(1) one of your classes has not got a <cache> tag
(2) I have no idea if the query cache is enabled using the system property


Top
 Profile  
 
 Post subject: Enabled Query Cache
PostPosted: Wed Feb 09, 2005 9:20 am 
Beginner
Beginner

Joined: Tue Jan 11, 2005 5:50 am
Posts: 43
Location: Zurich (Suisse)
Thank you Gavin.

I've already corrected the cache tag and inserted in the mapping.

Just to show you my cache configurations:

Code:
<hibernate-configuration>
   <session-factory>      
      <property name="show_sql">true</property>
      <property name="dialect">net.sf.hibernate.dialect.MySQLDialect</property>
      <property name="driver_class">com.mysql.jdbc.Driver</property>
      <property name="connection.url">jdbc:mysql://python.passion.ch/mmscms?autoReconnect=true</property>
      <property name="connection.username">mmscms</property>
      <property name="connection.password">z79oqi</property>
      <property name="c3p0.min_size">5</property>
      <property name="c3p0.max_size">20</property>
      <property name="c3p0.timeout">300</property>
      <property name="c3p0.max_statements">50</property>
      <property name="c3p0.idle_test_period">3000</property>
      <property name="cache.provider_class">net.sf.ehcache.hibernate.Provider</property>
      <property name="max_fetch_depth">2</property>
      <property name="use_query_cache">true</property>
      <!-- Mapping files -->
      <mapping resource="com\someCompany\MMSCAdmin\beans\Login.hbm.xml"/>
      <mapping resource="com\someCompany\MMSCAdmin\beans\Keyword.hbm.xml"/>
      <mapping resource="com\someCompany\MMSCAdmin\beans\Service.hbm.xml"/>
      <mapping resource="com\someCompany\MMSCAdmin\beans\MMSAbo.hbm.xml"/>
   </session-factory>
</hibernate-configuration>



<ehcache>
   
   <defaultCache maxElementsInMemory="10000" eternal="false" timeToIdleSeconds="1200" timeToLiveSeconds="1200" overflowToDisk="true"/>
          
    <cache name="com.mobilelogix.MMSCAdmin.beans.MMSAbo"
        maxElementsInMemory="10000"
        eternal="false"
        timeToIdleSeconds="300"
        timeToLiveSeconds="600"
        overflowToDisk="true"
        />    
       
    <cache name="com.mobilelogix.MMSCAdmin.beans.Keyword"
        maxElementsInMemory="10000"
        eternal="false"
        timeToIdleSeconds="300"
        timeToLiveSeconds="600"
        overflowToDisk="true"
        />    
       
    <cache name="com.mobilelogix.MMSCAdmin.beans.Service"
        maxElementsInMemory="10000"
        eternal="false"
        timeToIdleSeconds="300"
        timeToLiveSeconds="600"
        overflowToDisk="true"
        />    
   <!-- Sample cache named sampleCache2
        This cache contains 1000 elements. Elements will always be held in memory.
        They are not expired.
    <cache name="my.package.Class.collection"
        maxElementsInMemory="1000"
        eternal="true"
        overflowToDisk="false"
        /> -->
   <!-- Place configuration for your caches following -->
</ehcache>

[/b]


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 09, 2005 9:23 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
hibernate.cache.use_query_cache

re-read the docs


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 09, 2005 9:38 am 
Beginner
Beginner

Joined: Tue Jan 11, 2005 5:50 am
Posts: 43
Location: Zurich (Suisse)
Gavin, thank you very much.

There is a difference now. Sorry for that "silly" typo :-)

Thanks a lot again.
Regards
Tarik


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