Hi,
I have a problem with HQL and querying a map attribute.
Here is my mapping file of a class Service.
Code:
<class name="com.eurecia.backoffice.Service" table="SERVICE_EA">
...
<map name="descr" table="SERVICE_DESCR_EA" cascade="all" lazy="false">
<key>
<column name="ID_SERVICE" not-null="true"/>
<column name="ID_COMPANY" not-null="true"/>
</key>
<map-key column="LOCALE" type="java.lang.String" length="10"/>
<element column="DESCR_SERVICE" type="java.lang.String" not-null="true" length="255"/>
</map>
Like you can see, this class contains a map attribute named
descr I would like to query this class et get the
descr for the current
locale.
So here is my query :
Code:
StringBuffer queryString = new StringBuffer();
queryString.append("SELECT srv.id.idService, srv.id.idCompany, srv.type,srv.descr['"+session.getLocale()+"'], cny.descr");
queryString.append(" FROM Service as srv, Company as cny");
queryString.append(" WHERE srv.id.idCompany = cny.id");
if( filters != null )
{
queryString.append(" AND srv.id.idService like '%"+filters.get("id.idService")+"%'");
queryString.append(" AND cny.descr like '%"+filters.get("companyDescr")+"%'");
queryString.append(" AND srv.type like '%"+filters.get("type")+"%'");
queryString.append(" AND srv.descr['"+session.getLocale()+"'] like '%"+filters.get("descr")+"%'");
}
My problem is in the SELECT part :
Code:
srv.descr['"+session.getLocale()+"']
. I think this expression can't be used in a SELECT section.
But it works in the WHERE section :
Code:
AND srv.descr['"+session.getLocale()+"'] like '%"+filters.get("descr")+"%
How can I select on element of a map in the SELECT section ?
Thank you for your response.
Hibernate version: 3.0.5