I am using the query cache and filters as the mapping and code below
shows.
Well my problem is that the query cache does not use the filter parameter as part of the key as evident from the toString below. The result is that I get a leakage between different filters.
/Konstantin
PS Everything works fine when the cache is disabled
Hibernate version:3.01
Mapping documents:
<hibernate-mapping>
<class name="MenuElementInfo" table="CMT_MENU_ELEMENTS">
<cache usage="nonstrict-read-write"/>
<id name="id" unsaved-value="-1"> <column name="element_id"/> <generator class="native"> <param name="sequence">CMT_MENU_ELEMENT_SEQ</param> </generator> </id>
<property name="menuText" column="element_txt"/>
<property name="menuLink" column="element_link"/>
<property name="altText"/>
<property name="titleText"/>
<property name="publicName"/>
<property name="edition"/>
<property name="parentId" column="parent_id" type="int" insert="false" update="false"/>
<many-to-one name="parentImpl" column="parent_id" class="se.posten.pse.verktyg.cmt.MenuElementInfo"/>
<list name="children" outer-join="true" lazy="true" cascade="all"> <cache usage="nonstrict-read-write"/> <key column="parent_id"/> <index column="order_id"/>
<one-to-many class="se.posten.pse.verktyg.cmt.MenuElementInfo"/> </list>
<filter name="editionFilter" condition=":editionParam = edition"/>
</class>
<!-- remove when menus are a part of the same schema as the rest of cmt --> <filter-def name="editionFilter"> <filter-param name="editionParam" type="string"/> </filter-def>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
session.enableFilter("editionFilter").setParameter("editionParam", Editions.getEdition()); MenuElementInfo menuElementInfo = (MenuElementInfo) sessionIn.createCriteria(MenuElementInfo.class) .add(Expression.eq("publicName", publicName)).setCacheable(true).uniqueResult();
Full stack trace of any exception that occurs:
Name and version of the database you are using:
The generated SQL (show_sql=true):
SQL against db: select this_.element_id as element1_1_, this_.element_txt as element2_0_1_, this_.element_link as element3_0_1_, this_.altText as altText0_1_, this_.titleText as titleText0_1_, this_.publicName as publicName0_1_, this_.edition as edition0_1_, this_.parent_id as parent8_0_1_, children2_.parent_id as parent8___, children2_.element_id as element1___, children2_.order_id as order9___, children2_.element_id as element1_0_, children2_.element_txt as element2_0_0_, children2_.element_link as element3_0_0_, children2_.altText as altText0_0_, children2_.titleText as titleText0_0_, children2_.publicName as publicName0_0_, children2_.edition as edition0_0_, children2_.parent_id as parent8_0_0_ from CMT_MENU_ELEMENTS this_ left outer join CMT_MENU_ELEMENTS children2_ on this_.element_id=children2_.parent_id where ? = this_.edition and this_.publicName=?
SQL query cache key (toString()): sql: select this_.element_id as element1_1_, this_.element_txt as element2_0_1_, this_.element_link as element3_0_1_, this_.altText as altText0_1_, this_.titleText as titleText0_1_, this_.publicName as publicName0_1_, this_.edition as edition0_1_, this_.parent_id as parent8_0_1_, children2_.parent_id as parent8___, children2_.element_id as element1___, children2_.order_id as order9___, children2_.element_id as element1_0_, children2_.element_txt as element2_0_0_, children2_.element_link as element3_0_0_, children2_.altText as altText0_0_, children2_.titleText as titleText0_0_, children2_.publicName as publicName0_0_, children2_.edition as edition0_0_, children2_.parent_id as parent8_0_0_ from CMT_MENU_ELEMENTS this_ left outer join CMT_MENU_ELEMENTS children2_ on this_.element_id=children2_.parent_id where :editionFilter.editionParam = this_.edition and this_.publicName=?; parameters: Svenska,
Debug level Hibernate log excerpt:
|