-->
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.  [ 11 posts ] 
Author Message
 Post subject: How does the 2nd level cache work ?
PostPosted: Tue May 25, 2004 4:26 am 
Beginner
Beginner

Joined: Wed May 12, 2004 4:27 am
Posts: 21
Location: Montreux (CH)
I would like to load the structure at once !

core_usergroup(id:int, name:varchar)
core_usermembership(usergroup_child:int, usergroup_parent:int)
core_userpassword(usergroup_id:int,data:datetime,value:varchar)

how can I do ?? ok fetch join I was answered... but how ?
session.find("From CoreUsergroup as user left join fetch user.children left join fetch user.parents left join fetch user.coreUserPasswords") ?

once in cache, I would like to have the list of all usergroups to handle it by myself... how to ?
iterate("From CoreUsergroup") ? it still does a sql request to retreive IDs... I don't want that ! And if I delete an object, the next time I call iterate, it still gives me the deleted ID and it crashes in IterateImpl)

I don't understand how the cache work ! Could someone explain ? Or is there any article to read on this ?


This is what I have :

I have a usergroup table that can contains other usergroups and be contained in other usergroups.
A usergroup also has a list of password (don't ask why)

Here is my xml :

Quote:
<hibernate-mapping>
<class name="test.CoreUsersgroup"
table="core_usersgroups" dynamic-update="false" dynamic-insert="false">

<cache usage="read-write" />

<id name="id" column="id" type="java.lang.Integer" unsaved-value="-1" >
<generator class="hilo">
<param name="table">hibernate_unique_key</param>
<param name="column">core_usersgroups</param>
<param name="max_lo">0</param>
</generator>
</id>

<property name="name" type="java.lang.String" update="true" insert="true" column="name" length="50" not-null="true"/>

<set name="children" lazy="false" inverse="true" cascade="delete" sort="unsorted">
<cache usage="read-write" />
<key column="usergroup_child" />
<one-to-many class="test.CoreUserMembership" />
</set>

<set name="parents" lazy="false" inverse="true" cascade="delete" sort="unsorted">
<cache usage="read-write" />
<key column="usergroup_parent" />
<one-to-many class="test.CoreUserMembership" />
</set>

<set name="coreUserPasswords" lazy="false" inverse="false" cascade="delete" sort="unsorted">
<cache usage="read-write" />
<key column="usergroup_id" />
<one-to-many class="test.CoreUserPassword" />
</set>
</class>

</hibernate-mapping>


Thank you very much


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 25, 2004 6:09 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
1- only one collection can be fetch
2- what you need in addition of second level cache is a query cache.

By doing this, if you call twice exactly the same query, it will not hit the db.

Try it, all is explained is the reference doc

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


Top
 Profile  
 
 Post subject: it's poor for caching
PostPosted: Tue May 25, 2004 11:22 am 
Beginner
Beginner

Joined: Wed May 12, 2004 4:27 am
Posts: 21
Location: Montreux (CH)
Hello,

thank you for your answer...

I'm very disappointed of your answer, it's a very basic approach of caching...

Am I the only one on earth ;o) to use the cache so much ??
I would appreciate if someone that often uses caching technics could contact me...

I can not load in memory all my data with hibernate, because I have more than one fetch to do...

What could I do ? Before discovering Hibernate, I made my own framework to handle persistence and cache. I don't like to reinvent the wheel, so I would like to find a way to use Hibernate... even if I just use it to load each table one by one... to avoid creating sql request...

thank you anthony !


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 25, 2004 11:35 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
my answer was unclear,
only one fetch is possible to load in one shot one of your objects' collection

so i'll try to explain better, what you can do:
1- 1rst query (must be defined as cacheable, see the doc to know how it works) from Obj as myObj fetch join myObj.collectionA
2- query.iterate() for example
3- 2nd query (must also be cacheable) from Obj as myObj fetch join myObj.collectionB
4- query.iterate()
5- At this point, normally your objects and their 2 collections are filled in only 2 queries
6- from now, every time you execute query 1 or query 2, it should not hit the since the queries, the class and the collections are cached too

don't forget to defined the 2 collections cacheable.

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


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 23, 2004 1:40 am 
Beginner
Beginner

Joined: Fri Jan 23, 2004 4:29 pm
Posts: 39
I have the same problem.

When I delete an object it still shows up in a collection and fails on lazy loading.

Did you manage to fix that?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 23, 2004 2:48 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
how is it related with this post?

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


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 23, 2004 3:03 am 
Beginner
Beginner

Joined: Fri Jan 23, 2004 4:29 pm
Posts: 39
anthony wrote:
once in cache, I would like to have the list of all usergroups to handle it by myself... how to ?
iterate("From CoreUsergroup") ? it still does a sql request to retreive IDs... I don't want that ! And if I delete an object, the next time I call iterate, it still gives me the deleted ID and it crashes in IterateImpl)


After I delete an object that is in a collection. The cache still contains the deleted object's key. And tries to lazy load it from the database. When I access the collection.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 23, 2004 4:25 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
have you removed the object from the collection?

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


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 23, 2004 4:34 am 
Beginner
Beginner

Joined: Fri Jan 23, 2004 4:29 pm
Posts: 39
anthony wrote:
have you removed the object from the collection?


I have not done that. Should not Hibernate do that if i specify cascade="all"?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 23, 2004 4:47 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
read about parent/child relationship please and if you cannot find a way to parameter the association ... come back ;)

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


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 23, 2004 5:20 am 
Beginner
Beginner

Joined: Fri Jan 23, 2004 4:29 pm
Posts: 39
I read the Parent/Child example twice. But it does not clearly state what happens in my case.

It says among other things:
<i>
To tighten things up a bit, we could create an addChild() method of Parent.
public void addChild(Child c) {
c.setParent(this);
children.add(c);
}
</i>

In my case I delete an object not through the collection of the parent object. But directly through session.delete()
So I guess I have to call parent.getChildren().remove() also.


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