-->
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.  [ 4 posts ] 
Author Message
 Post subject: Caching Maps or Sets: deletions and inserts/no cache expire?
PostPosted: Thu Sep 16, 2004 8:03 am 
Newbie

Joined: Thu Sep 16, 2004 7:37 am
Posts: 2
Hi,

we've encountered a problem with caching and we're not sure if the behaviour is wanted or not.

We use EHCache (version 0.7 and tried also 0.9) and also changed the Hibernate release from 2.1.3 to 2.1.6 but had the same effects.

These are as follows: we use second level caching for objects and for queries, too. Everything works fine. Updates, inserts and deletes lead to cache expires either in the appropriate object or query cache.
To improve our application's performance we then tried to enable cache for out lazily evaluated set or map properties (collection mappings), too.
That means, we added the line

<cache usage="read-write"/>

for some set or map properties. Let's say: if we access e.g. Father.children() the query that results in accessing the children should have been cached, too.

The results are cached, but if a child is deleted, this cached query won't be expired. This leads to an exception when accessing the mapped collection: an id of an deleted object is still part of the collection and this leads to an exception.
If we would use a query-object with setCacheable(true), everything would work well.

As a result, the option to enable caching for collection mappings is totally useless for us since we don't have read-only operations.

Have I overread something in the docu or misunderstood the idea of caching collections?

Help and info is highly appreciated
Thanks in advance

Markus



Hibernate version:2.1.3 and 2.1.6

Mapping documents:
Since our mapping is very complex I just post a part of it but it should be informative enough... if not, I'll post the rest - but that's a lot....

<hibernate-mapping>

<class name="com.pironet.projects.metro.mam.WebStandorte" table="WEB_STANDORTE">
<meta inherit="true" attribute="implement-equals">true</meta>
<cache usage="read-write"/>
<id name="id" type="integer" column="ID">
<meta attribute="field-description"></meta>
<meta attribute="finder-method">findById</meta>
<generator class="sequence">
<param name="sequence">standorte_sequence</param>
</generator>
</id>
<property name="pirobase_id" type="integer" not-null="false">
<meta attribute="finder-method">findByPirobaseID</meta>
</property>
<property name="adresse1" type="string" not-null="false"/>
<property name="adresse2" type="string" not-null="false"/>
<property name="einwohner10" type="int" not-null="false"/>
<property name="einwohner20" type="int" not-null="false"/>
<property name="einwohner30" type="int" not-null="false"/>
<property name="einwohnergesamt" type="int" not-null="false"/>
<property name="eroeffnung" type="string" not-null="false"/>
<property name="kaufkraft" type="int" not-null="false"/>
<property name="mail" type="string" not-null="false"/>
<property name="gesamtflaeche" type="int" not-null="false"/>
<property name="mietflaeche" type="int" not-null="false"/>
<property name="parkplaetze" type="int" not-null="false"/>
<property name="picturefolder" type="string" not-null="false"/>
<property name="mins_id" type="string" not-null="false"/>
<property name="ort" type="string" not-null="false">
<meta attribute="finder-method">findByOrt</meta>
</property>
<property name="telefon" type="string" not-null="false"/>
<property name="telefax" type="string" not-null="false"/>
<property name="webadresse" type="string" not-null="false"/>
<property name="webshow" type="int" not-null="false">
<meta attribute="finder-method">findAllOnWebsite</meta>
</property>
<set name="shop" lazy="true" inverse="true" cascade="all">
<cache usage="read-write"/>
<key column="ID_WEB_STANDORTE"/>
<one-to-many class="com.pironet.projects.metro.mam.WebShop"/>
</set>
</class>

....

<class name="com.pironet.projects.metro.mam.WebShop" table="WEB_SHOPS">
<meta inherit="true" attribute="implement-equals">true</meta>
<cache usage="read-write"/>
<id name="id" type="integer" column="ID">
<meta attribute="finder-method">findById</meta>
<generator class="sequence">
<param name="sequence">shops_sequence</param>
</generator>
</id>
<property name="telefon" type="string" not-null="false"/>
<property name="telefax" type="string" not-null="false"/>
<property name="mail" type="string" not-null="false"/>
<property name="webadresse" type="string" not-null="false"/>
<property name="gastronomie" type="int" not-null="false"/>
<property name="pictureid_lageplan" type="integer" not-null="false"/>
<property name="pictureid_logo" type="integer" not-null="false"/>
<property name="pictureid_icon" type="integer" not-null="false"/>
<property name="aktionsprodukte" type="int" not-null="false">
<meta attribute="finder-method">findAllAktionsprodukteanbieter</meta>
</property>
<property name="ankermieter" type="int" not-null="false">
<meta attribute="finder-method">findAllAnkermieter</meta>
</property>
<property name="mietflaeche_mre" type="int" not-null="false"/>
<property name="show_mre" type="int" not-null="false">
<meta attribute="finder-method">findAllOnWebsite</meta>
</property>
<property name="show_center" type="int" not-null="false">
<meta attribute="finder-method">findAllOnCentersite</meta>
</property>
<property name="mvnummer" type="string" not-null="false"/>
<property name="shopumgebung" type="int" not-null="false"/>
<map name="webShopLang" lazy="true" order-by="name asc" sort="natural" inverse="true" cascade="all">
<key column="ID_WEB_SHOP"/>
<index column="LANG_ID" type="integer"/>
<one-to-many class="com.pironet.projects.metro.mam.WebShopLang"/>
</map>
<set name="jobs" lazy="true" inverse="true" cascade="delete">
<key column="ID_WEB_SHOP"/>
<one-to-many class="com.pironet.projects.metro.mam.WebJob"/>
</set>
<set name="produkte" lazy="true" inverse="true" cascade="all">
<key column="ID_WEB_SHOP"/>
<one-to-many class="com.pironet.projects.metro.mam.WebProdukt"/>
</set>
<set name="branchen" table="BRANCHE_WEB_SHOPS" lazy="true" cascade="delete">
<key column="ID_WEB_SHOP"/>
<many-to-many column="ID_BRANCHE" class="com.pironet.projects.metro.mam.Branche"/>
</set>
<set name="sortiment" table="SORTIMENT_WEB_SHOPS" lazy="true" cascade="delete">
<key column="ID_WEB_SHOP"/>
<many-to-many column="ID_SORTIMENT" class="com.pironet.projects.metro.mam.Sortiment"/>
</set>
<many-to-one name="standort" class="com.pironet.projects.metro.mam.WebStandorte" column="ID_WEB_STANDORTE"/>
<many-to-one name="gastrotyp" class="com.pironet.projects.metro.mam.Gastrotyp" column="ID_GASTROTYP"/>
</class>
</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 16, 2004 8:15 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Did you remove things from associations (collections) before deleting them?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 16, 2004 9:01 am 
Newbie

Joined: Thu Sep 16, 2004 7:37 am
Posts: 2
No, we didn't... should we? What if an object is linked to multiple parent-objects? Would that be lets say "against" the basic idea?
Should we then take care that it's deleted from every parent mapping?

Thanks in advance
Markus


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 16, 2004 9:14 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
Quote:
Should we then take care that it's deleted from every parent mapping?


You should always care about instances and model integrity, no matter how cascade is set. A model is a model, instances and associations must be ok.

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


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