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):