-->
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.  [ 2 posts ] 
Author Message
 Post subject: Second level caching collections - n+1 problem
PostPosted: Fri Dec 07, 2007 1:21 pm 
Newbie

Joined: Fri Dec 07, 2007 1:01 pm
Posts: 2
Hello everybody

I am Bert and I am part of the team of weewar.com a turn based strategy game.

In advance: Hibernate is great. I want to thank the developers and the open source community for creating such a great product.

My problem concerns a cached collections. I am using a second level cache (ehcache). All essential mapping documents can be found below.

Here is my problem:

My application loads an object of class "EventCollection" that contains a cached collection that consists of objects of class "Event". The contents of this collection is loaded using the fetch="join" attribute once the EventCollection is loaded. Hence all this is done with one single sql query.

I can now access the EventCollection and the containing Events as I like and no futher sql queryies are made.

Everything works fine until Events expire from the second level cache. If I access the events after that each Event is loaded with one sql statement.

Thanks a lot

Bert

Hibernate version: 3.1.3

Mapping documents:

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
<hibernate-mapping package="com.weewar.model">
<class
name="EventCollection"
table="EventCollection"
>
<meta attribute="sync-DAO">true</meta>
<cache usage="read-write"/>
<id
name="Id"
type="integer"
column="collection_id"
>
<generator class="native"/>
</id>

<list name="events" fetch="join" lazy="false">
<key column="collection_id" />
<list-index column="position" />
<one-to-many class="Event" />
</list>

</class>

<class
name="Event"
table="Event"
batch-size="300"
>
<meta attribute="sync-DAO">true</meta>
<cache usage="read-write"/>
<id
name="Id"
type="integer"
column="event_id"
>
<generator class="native"/>
</id>

<property
name="timestamp"
column="timestamp"
type="timestamp"
/>

<property
name="position"
column="position"
type="int"
length="11"
/>
<many-to-one
name="eventCollection"
column="collection_id"
class="EventCollection"
/>
<many-to-one
name="player"
column="player_id"
class="Player"
/>

<!-- ommitted lots of properties here -->

</class>
</hibernate-mapping>

hibernate.cfg.xml contains the following entry:

<collection-cache collection="com.weewar.model.EventCollection.events" usage="read-write"/>



Name and version of the database you are using:

MySql 5.0

Read this: http://hibernate.org/42.html


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 10, 2007 7:58 am 
Newbie

Joined: Fri Dec 07, 2007 1:01 pm
Posts: 2
Good morning. I am still working on this. Right now I have enlarged the cache size of the Event Objects to guarantee that Events will never expire before the EventCollection Objects. It looks as if this makes the thing work but still it feels more like a work arround and I am curious if there are "real" solutions to this problem


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