Hello
Sorry if I might bother someone. Some people helped me to step into a better situation but there is still one issue which I cannot solve.
The initial issue was that if I joined tables the resultset was not distinct and so I got indistinct results in the parent/child relationship of service/mmsAbo. In fact I had 1000 services where there should have been only 100.
Someone helped me out and advised me to use a hashset over the list returned from the query, which I did. But now I ran into another issue - the results were not ordered.
Is there a way to receive an ordered result set in my scenario without sorting programmatically?
Or is there a better solution for my query, using a different mapping, or something else?
Any help, advice greatly appreciated.
Regards
Tarik
Hibernate version:
2
Mapping documents:
Code:
<hibernate-mapping>
<class name="com.someCompany.MMSCAdmin.beans.Service" table="SERVICE" lazy="true" batch-size="20" >
<cache usage="read-write"/>
<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.mobilelogix.MMSCAdmin.beans.Service as service
left join fetch service.abos as abo
where abo.senddateStart >= :senddateStart
and abo.senddateEnd <= :senddateEnd
]]></query>
</hibernate-mapping>
hibernate-mapping>
<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>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():Code:
/**
* @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