-->
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.  [ 8 posts ] 
Author Message
 Post subject: EHCache configured but not used?
PostPosted: Tue Apr 25, 2006 2:34 pm 
Beginner
Beginner

Joined: Wed Apr 05, 2006 3:19 pm
Posts: 43
I'm using the generic daofactory from the documentation. Imagine I want a certain user. Also imagine I would want to do this:

Code:
User user = daofactory.getUser(userName);
User theSameUser = daofactory.getUser(userName);


Then I get this output.

Code:
Hibernate:
    select
        this_.userID as userID8_0_,
        this_.userName as userName8_0_,
        this_.password as password8_0_,
        this_.email as email8_0_,
        this_.firstName as firstName8_0_,
        this_.familyName as familyName8_0_,
        this_.regDate as regDate8_0_,
        this_.activeDate as activeDate8_0_,
        this_.ip as ip8_0_,
        this_.host as host8_0_,
        this_.up as up8_0_,
        this_.xp as xp8_0_,
        this_.money as money8_0_,
        this_.rankID as rankID8_0_,
        this_.teamID as teamID8_0_
    from
        users this_
    where
        this_.userName=?
Hibernate:
    select
        this_.userID as userID8_0_,
        this_.userName as userName8_0_,
        this_.password as password8_0_,
        this_.email as email8_0_,
        this_.firstName as firstName8_0_,
        this_.familyName as familyName8_0_,
        this_.regDate as regDate8_0_,
        this_.activeDate as activeDate8_0_,
        this_.ip as ip8_0_,
        this_.host as host8_0_,
        this_.up as up8_0_,
        this_.xp as xp8_0_,
        this_.money as money8_0_,
        this_.rankID as rankID8_0_,
        this_.teamID as teamID8_0_
    from
        users this_
    where
        this_.userName=?


This means hibernate (some daofactory method) selects the user twice from the database, although EHCache is enabled. Isn't it possible for hibernate to get the user from the cache instead of the database?

EHCache also warns about configuration:

Code:
20:40:06,812  WARN EhCacheProvider:103 - Could not find configuration [objects.User]; using defaults.


but I do have a configuration:

Code:
<class name="objects.User" table="users">
      <cache usage="nonstrict-read-write" />
      <id name="userID" column="userID">
            <generator class="native" />
        </id>
        <property name="userName" />
        <property name="pass........etc

_________________
Don't forget to rate my post if it helped. :)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 26, 2006 2:45 am 
Beginner
Beginner

Joined: Wed Apr 05, 2006 3:19 pm
Posts: 43
Anybody who knows what's going on here?

_________________
Don't forget to rate my post if it helped. :)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 26, 2006 5:40 am 
Newbie

Joined: Mon Apr 24, 2006 11:43 am
Posts: 4
Location: Edinburgh
Make sure your ehcache.xml is at the top level of your har and not in any meta-inf directoy.


Theres a good guide on how to do it here.

http://www.javalobby.org/java/forums/t48846.html

Andrew A.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 26, 2006 7:22 am 
Beginner
Beginner

Joined: Wed Apr 05, 2006 3:19 pm
Posts: 43
AndrewWA wrote:
Make sure your ehcache.xml is at the top level of your har and not in any meta-inf directoy.


Theres a good guide on how to do it here.

http://www.javalobby.org/java/forums/t48846.html

Andrew A.


What do you mean with "har"?

I've placed ehcache.xml in the classpath, if that's what you mean... (I put it in the source directory, it then gets copied in the build process by eclipse [ide]).

Anyway, thanks for the url to the website. I read it and it's quite a good article. I have a better understanding of how the caches work, but it didn't solve my problem.

_________________
Don't forget to rate my post if it helped. :)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 26, 2006 8:05 am 
Newbie

Joined: Mon Apr 24, 2006 11:43 am
Posts: 4
Location: Edinburgh
Do you have objects.User specified in your ehcache.xml file like this?

<cache name="objects.User"
maxElementsInMemory="10000"
eternal="false"
timeToIdleSeconds="300"
timeToLiveSeconds="600"
overflowToDisk="false"
/>

Thats seems the most likly candidate.

Andrew A.


Top
 Profile  
 
 Post subject: Re: EHCache configured but not used?
PostPosted: Thu Apr 27, 2006 4:05 am 
Newbie

Joined: Thu Apr 27, 2006 3:55 am
Posts: 4
Hello,

the warning about the missing ehcache configuration can be ignored,
this isn't the cause of your problem.
You have to take a closer look at your dao method.
If this is retrieving the data using a criteria, make sure to call Criteria.setCacheable(true).

Laurens wrote:
Code:
User user = daofactory.getUser(userName);
User theSameUser = daofactory.getUser(userName);



EHCache also warns about configuration:

Code:
20:40:06,812  WARN EhCacheProvider:103 - Could not find configuration [objects.User]; using defaults.


but I do have a configuration:

Code:
<class name="objects.User" table="users">
      <cache usage="nonstrict-read-write" />
      <id name="userID" column="userID">
            <generator class="native" />
        </id>
        <property name="userName" />
        <property name="pass........etc


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 28, 2006 1:19 pm 
Beginner
Beginner

Joined: Wed Apr 05, 2006 3:19 pm
Posts: 43
I'm currently using the "setcachable(true)" and natural identifiers, but hibernate still seems to be selecting from the database instead of the cache.

This is the output:

Code:
19:22:10,843 DEBUG SQL:346 -
    select
        this_.userID as userID8_0_,
        this_.userName as userName8_0_,
        this_.password as password8_0_,
        this_.email as email8_0_,
        this_.firstName as firstName8_0_,
        this_.familyName as familyName8_0_,
        this_.regDate as regDate8_0_,
        this_.activeDate as activeDate8_0_,
        this_.ip as ip8_0_,
        this_.host as host8_0_,
        this_.up as up8_0_,
        this_.xp as xp8_0_,
        this_.money as money8_0_,
        this_.rankID as rankID8_0_,
        this_.teamID as teamID8_0_
    from
        users this_
    where
        (
            this_.userName=?
        )
Hibernate:
    select
        this_.userID as userID8_0_,
        this_.userName as userName8_0_,
        this_.password as password8_0_,
        this_.email as email8_0_,
        this_.firstName as firstName8_0_,
        this_.familyName as familyName8_0_,
        this_.regDate as regDate8_0_,
        this_.activeDate as activeDate8_0_,
        this_.ip as ip8_0_,
        this_.host as host8_0_,
        this_.up as up8_0_,
        this_.xp as xp8_0_,
        this_.money as money8_0_,
        this_.rankID as rankID8_0_,
        this_.teamID as teamID8_0_
    from
        users this_
    where
        (
            this_.userName=?
        )
19:22:10,984 DEBUG ReadWriteCache:148 - Caching: objects.User#1
19:22:10,984 DEBUG EhCache:104 - key: objects.User#1
19:22:10,984 DEBUG EhCache:113 - Element for objects.User#1 is null
19:22:10,984 DEBUG ReadWriteCache:160 - Cached: objects.User#1
19:22:11,031 DEBUG SQL:346 -
    select
        this_.userID as userID8_0_,
        this_.userName as userName8_0_,
        this_.password as password8_0_,
        this_.email as email8_0_,
        this_.firstName as firstName8_0_,
        this_.familyName as familyName8_0_,
        this_.regDate as regDate8_0_,
        this_.activeDate as activeDate8_0_,
        this_.ip as ip8_0_,
        this_.host as host8_0_,
        this_.up as up8_0_,
        this_.xp as xp8_0_,
        this_.money as money8_0_,
        this_.rankID as rankID8_0_,
        this_.teamID as teamID8_0_
    from
        users this_
    where
        (
            this_.userName=?
        )
Hibernate:
    select
        this_.userID as userID8_0_,
        this_.userName as userName8_0_,
        this_.password as password8_0_,
        this_.email as email8_0_,
        this_.firstName as firstName8_0_,
        this_.familyName as familyName8_0_,
        this_.regDate as regDate8_0_,
        this_.activeDate as activeDate8_0_,
        this_.ip as ip8_0_,
        this_.host as host8_0_,
        this_.up as up8_0_,
        this_.xp as xp8_0_,
        this_.money as money8_0_,
        this_.rankID as rankID8_0_,
        this_.teamID as teamID8_0_
    from
        users this_
    where
        (
            this_.userName=?
        )
19:22:11,046 DEBUG ReadWriteCache:148 - Caching: objects.User#1
19:22:11,046 DEBUG EhCache:104 - key: objects.User#1
19:22:11,046 DEBUG ReadWriteCache:169 - Item was already cached: objects.User#1


Especially this part is interesting (somewhere between the two selects):
Code:
19:22:10,984 DEBUG ReadWriteCache:148 - Caching: objects.User#1
19:22:10,984 DEBUG EhCache:104 - key: objects.User#1
19:22:10,984 DEBUG EhCache:113 - Element for objects.User#1 is null


and then this (at the end)
Code:
19:22:11,046 DEBUG ReadWriteCache:148 - Caching: objects.User#1
19:22:11,046 DEBUG EhCache:104 - key: objects.User#1
19:22:11,046 DEBUG ReadWriteCache:169 - Item was already cached:

_________________
Don't forget to rate my post if it helped. :)


Top
 Profile  
 
 Post subject:
PostPosted: Sat Apr 29, 2006 1:37 pm 
Beginner
Beginner

Joined: Wed Apr 05, 2006 3:19 pm
Posts: 43
Anyone? 2nd level caching works for some objects (retrieved by ID), but this one doesn't seem to work.

_________________
Don't forget to rate my post if it helped. :)


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