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.  [ 7 posts ] 
Author Message
 Post subject: Hibernate + ehcache + extended classes: trouble :)
PostPosted: Fri Jan 04, 2008 9:53 am 
Newbie

Joined: Fri Jan 04, 2008 9:19 am
Posts: 4
greetings folks :) I have a problem with caching with ehcache + hibernate.

I have a base class (class A) which is extended by four classes (B, C, D, E). The four classes are actually the ones used in the code to perform loads, queries, save and whatever needed. This reflects an is-a relationship on the database. The classes are mapped like that:

Code:
<class name="it.mycompany.A" table="a_table"  lazy="true">
[...]
   <joined-subclass name="it.mycompany.B" table="b_table" lazy="true">
      [...]
   </joined-subclass>
   <joined-subclass name="it.mycompany.C" table="c_table" lazy="true">
      [...]
   </joined-subclass>
</class>


I need to boost my application's performance, so I enabled caching: I've added a default ehcache.cfg.xml file (copied straight from the tutorial) and added the following line on hibernate.cfg.xml:

<class-cache class="it.mycompany.B" usage="read-write"/>

ehcache starts correctly and caches other entities in the mapping. However, if I add the line above, I get a message like

"You may only specify a cache for root <class> mappings"

however, it's the child classes I need cached, because those are the ones that are used with the code... hibernate generates joined queries, and having just the superclass cached would do me no good.

Thanks in advance for any help, I'm really at a loss here.

Hibernate version: hibernate 3 + ehcache 1.0

Mapping documents: specified in message

Full stack trace of any exception that occurs:
Code:
2008-01-04 14:44:03,039 FATAL [main] hibernate.HibernateUtil (HibernateUtil.java:70) - Creazione iniziale di una SessionFactory Hibernate fallita
org.hibernate.MappingException: You may only specify a cache for root <class> mappings
   at org.hibernate.cfg.Configuration.getRootClassMapping(Configuration.java:1402)
   at org.hibernate.cfg.Configuration.setCacheConcurrencyStrategy(Configuration.java:1422)
   at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1241)
   at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1217)
   at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1184)
   at org.hibernate.cfg.Configuration.configure(Configuration.java:1112)
   at org.hibernate.cfg.Configuration.configure(Configuration.java:1098)


Name and version of the database you are using: Mysql 5.0.27


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 04, 2008 11:59 am 
Expert
Expert

Joined: Mon Nov 26, 2007 2:29 pm
Posts: 443
Francesco,
Have you tried specifying

Code:
<cache="read-write"/>


at the mapping document of each concrete subclass?

_________________
Gonzalo Díaz


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 09, 2008 10:28 am 
Newbie

Joined: Fri Jan 04, 2008 9:19 am
Posts: 4
gonzao_diaz wrote:
Francesco,
Have you tried specifying

Code:
<cache="read-write"/>


at the mapping document of each concrete subclass?


there is no such thing as a concrete subclass mapping document. All classes extending A are mapped as "joined-subclass" on A's mapping document.

Adding cache-usage on the joined-subclass section won't work. Adding it to the main class table doesn't cache most of things.

It is impossible that Hibernate doesn't allow caching of derived objects... I must be wrong somewhere... any other ideas?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 11, 2008 9:05 pm 
Expert
Expert

Joined: Mon Nov 26, 2007 2:29 pm
Posts: 443
Yes. Put that cache-enabling tag in the parent class, ask for nice-formatted cache statistics, and check visually if the subclasses you expect are being cached at all.

_________________
Gonzalo Díaz


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 14, 2008 1:38 pm 
Newbie

Joined: Fri Jan 04, 2008 9:19 am
Posts: 4
gonzao_diaz wrote:
Yes. Put that cache-enabling tag in the parent class, ask for nice-formatted cache statistics, and check visually if the subclasses you expect are being cached at all.


Done :) but doesn't work.

Legenda: "Articolo" is the derived class ("B" in the example above). "Asseteditoriale" is the base class ("A") which is cached.

First call:

2008-01-14 18:28:22,964 DEBUG [http-8080-Processor25] ehcache.Cache (Cache.java:878) - articolo now: 1200331702964
2008-01-14 18:28:22,964 DEBUG [http-8080-Processor25] ehcache.Cache (Cache.java:878) - articolo now: 1200331702964
2008-01-14 18:28:22,974 DEBUG [http-8080-Processor25] ehcache.Cache (Cache.java:879) - articolo Creation Time: 1200331702964 Next To Last Access Time: 0
2008-01-14 18:28:22,974 DEBUG [http-8080-Processor25] ehcache.Cache (Cache.java:879) - articolo Creation Time: 1200331702964 Next To Last Access Time: 0
2008-01-14 18:28:22,974 DEBUG [http-8080-Processor25] ehcache.Cache (Cache.java:881) - articolo mostRecentTime: 1200331702964
2008-01-14 18:28:22,974 DEBUG [http-8080-Processor25] ehcache.Cache (Cache.java:881) - articolo mostRecentTime: 1200331702964
2008-01-14 18:28:22,974 DEBUG [http-8080-Processor25] ehcache.Cache (Cache.java:882) - articolo Age to Idle: 120000 Age Idled: 0
2008-01-14 18:28:22,974 DEBUG [http-8080-Processor25] ehcache.Cache (Cache.java:882) - articolo Age to Idle: 120000 Age Idled: 0
2008-01-14 18:28:22,974 DEBUG [http-8080-Processor25] ehcache.Cache (Cache.java:906) - org.hibernate.cache.UpdateTimestampsCache: Is element with key articolo expired?: false
2008-01-14 18:28:22,974 DEBUG [http-8080-Processor25] ehcache.Cache (Cache.java:906) - org.hibernate.cache.UpdateTimestampsCache: Is element with key articolo expired?: false
2008-01-14 18:28:22,974 DEBUG [http-8080-Processor25] ehcache.Cache (Cache.java:878) - articolo now: 1200331702974
2008-01-14 18:28:22,974 DEBUG [http-8080-Processor25] ehcache.Cache (Cache.java:878) - articolo now: 1200331702974
2008-01-14 18:28:22,974 DEBUG [http-8080-Processor25] ehcache.Cache (Cache.java:879) - articolo Creation Time: 1200331702964 Next To Last Access Time: 0
2008-01-14 18:28:22,974 DEBUG [http-8080-Processor25] ehcache.Cache (Cache.java:879) - articolo Creation Time: 1200331702964 Next To Last Access Time: 0
2008-01-14 18:28:22,974 DEBUG [http-8080-Processor25] ehcache.Cache (Cache.java:881) - articolo mostRecentTime: 1200331702964
2008-01-14 18:28:22,974 DEBUG [http-8080-Processor25] ehcache.Cache (Cache.java:881) - articolo mostRecentTime: 1200331702964
2008-01-14 18:28:22,974 DEBUG [http-8080-Processor25] ehcache.Cache (Cache.java:882) - articolo Age to Idle: 120000 Age Idled: 10
2008-01-14 18:28:22,974 DEBUG [http-8080-Processor25] ehcache.Cache (Cache.java:882) - articolo Age to Idle: 120000 Age Idled: 10
2008-01-14 18:28:22,974 DEBUG [http-8080-Processor25] ehcache.Cache (Cache.java:906) - org.hibernate.cache.UpdateTimestampsCache: Is element with key articolo expired?: false
2008-01-14 18:28:22,974 DEBUG [http-8080-Processor25] ehcache.Cache (Cache.java:906) - org.hibernate.cache.UpdateTimestampsCache: Is element with key articolo expired?: false
2008-01-14 18:28:22,984 DEBUG [http-8080-Processor25] store.MemoryStore (MemoryStore.java:201) - it.inera.icms.db.AsseteditorialeCache: MemoryStore hit for it.inera.icms.db.Asseteditoriale#11017
2008-01-14 18:28:22,984 DEBUG [http-8080-Processor25] store.MemoryStore (MemoryStore.java:201) - it.inera.icms.db.AsseteditorialeCache: MemoryStore hit for it.inera.icms.db.Asseteditoriale#11017
2008-01-14 18:28:22,984 DEBUG [http-8080-Processor25] ehcache.Cache (Cache.java:878) - it.inera.icms.db.Asseteditoriale#11017 now: 1200331702984
2008-01-14 18:28:22,984 DEBUG [http-8080-Processor25] ehcache.Cache (Cache.java:878) - it.inera.icms.db.Asseteditoriale#11017 now: 1200331702984
2008-01-14 18:28:22,984 DEBUG [http-8080-Processor25] ehcache.Cache (Cache.java:879) - it.inera.icms.db.Asseteditoriale#11017 Creation Time: 1200331679420 Next To Last Access Time: 1200331698888
2008-01-14 18:28:22,984 DEBUG [http-8080-Processor25] ehcache.Cache (Cache.java:879) - it.inera.icms.db.Asseteditoriale#11017 Creation Time: 1200331679420 Next To Last Access Time: 1200331698888
2008-01-14 18:28:22,984 DEBUG [http-8080-Processor25] ehcache.Cache (Cache.java:881) - it.inera.icms.db.Asseteditoriale#11017 mostRecentTime: 1200331698888
2008-01-14 18:28:22,984 DEBUG [http-8080-Processor25] ehcache.Cache (Cache.java:881) - it.inera.icms.db.Asseteditoriale#11017 mostRecentTime: 1200331698888
2008-01-14 18:28:22,984 DEBUG [http-8080-Processor25] ehcache.Cache (Cache.java:882) - it.inera.icms.db.Asseteditoriale#11017 Age to Idle: 120000 Age Idled: 4096
2008-01-14 18:28:22,984 DEBUG [http-8080-Processor25] ehcache.Cache (Cache.java:882) - it.inera.icms.db.Asseteditoriale#11017 Age to Idle: 120000 Age Idled: 4096
2008-01-14 18:28:22,984 DEBUG [http-8080-Processor25] ehcache.Cache (Cache.java:906) - it.inera.icms.db.Asseteditoriale: Is element with key it.inera.icms.db.Asseteditoriale#11017 expired?: false
2008-01-14 18:28:22,984 DEBUG [http-8080-Processor25] ehcache.Cache (Cache.java:906) - it.inera.icms.db.Asseteditoriale: Is element with key it.inera.icms.db.Asseteditoriale#11017 expired?: false
2008-01-14 18:28:23,284 DEBUG [http-8080-Processor25] store.MemoryStore (MemoryStore.java:201) - it.inera.icms.db.AsseteditorialeCache: MemoryStore hit for it.inera.icms.db.Asseteditoriale#11017
2008-01-14 18:28:23,284 DEBUG [http-8080-Processor25] store.MemoryStore (MemoryStore.java:201) - it.inera.icms.db.AsseteditorialeCache: MemoryStore hit for it.inera.icms.db.Asseteditoriale#11017
2008-01-14 18:28:23,284 DEBUG [http-8080-Processor25] ehcache.Cache (Cache.java:878) - it.inera.icms.db.Asseteditoriale#11017 now: 1200331703284
2008-01-14 18:28:23,284 DEBUG [http-8080-Processor25] ehcache.Cache (Cache.java:878) - it.inera.icms.db.Asseteditoriale#11017 now: 1200331703284
2008-01-14 18:28:23,284 DEBUG [http-8080-Processor25] ehcache.Cache (Cache.java:879) - it.inera.icms.db.Asseteditoriale#11017 Creation Time: 1200331702994 Next To Last Access Time: 0
2008-01-14 18:28:23,284 DEBUG [http-8080-Processor25] ehcache.Cache (Cache.java:879) - it.inera.icms.db.Asseteditoriale#11017 Creation Time: 1200331702994 Next To Last Access Time: 0
2008-01-14 18:28:23,284 DEBUG [http-8080-Processor25] ehcache.Cache (Cache.java:881) - it.inera.icms.db.Asseteditoriale#11017 mostRecentTime: 1200331702994
2008-01-14 18:28:23,284 DEBUG [http-8080-Processor25] ehcache.Cache (Cache.java:881) - it.inera.icms.db.Asseteditoriale#11017 mostRecentTime: 1200331702994
2008-01-14 18:28:23,284 DEBUG [http-8080-Processor25] ehcache.Cache (Cache.java:882) - it.inera.icms.db.Asseteditoriale#11017 Age to Idle: 120000 Age Idled: 290
2008-01-14 18:28:23,284 DEBUG [http-8080-Processor25] ehcache.Cache (Cache.java:882) - it.inera.icms.db.Asseteditoriale#11017 Age to Idle: 120000 Age Idled: 290
2008-01-14 18:28:23,284 DEBUG [http-8080-Processor25] ehcache.Cache (Cache.java:906) - it.inera.icms.db.Asseteditoriale: Is element with key it.inera.icms.db.Asseteditoriale#11017 expired?: false
2008-01-14 18:28:23,284 DEBUG [http-8080-Processor25] ehcache.Cache (Cache.java:906) - it.inera.icms.db.Asseteditoriale: Is element with key it.inera.icms.db.Asseteditoriale#11017 expired?: false


after the caching

2008-01-14 18:33:31,818 DEBUG [http-8080-Processor25] store.MemoryStore (MemoryStore.java:201) - it.inera.icms.db.AsseteditorialeCache: MemoryStore hit for it.inera.icms.db.Asseteditoriale#880
2008-01-14 18:33:31,818 DEBUG [http-8080-Processor25] store.MemoryStore (MemoryStore.java:201) - it.inera.icms.db.AsseteditorialeCache: MemoryStore hit for it.inera.icms.db.Asseteditoriale#880
2008-01-14 18:33:31,818 DEBUG [http-8080-Processor25] ehcache.Cache (Cache.java:878) - it.inera.icms.db.Asseteditoriale#880 now: 1200332011818
2008-01-14 18:33:31,818 DEBUG [http-8080-Processor25] ehcache.Cache (Cache.java:878) - it.inera.icms.db.Asseteditoriale#880 now: 1200332011818
2008-01-14 18:33:31,818 DEBUG [http-8080-Processor25] ehcache.Cache (Cache.java:879) - it.inera.icms.db.Asseteditoriale#880 Creation Time: 1200331944802 Next To Last Access Time: 1200331985400
2008-01-14 18:33:31,818 DEBUG [http-8080-Processor25] ehcache.Cache (Cache.java:879) - it.inera.icms.db.Asseteditoriale#880 Creation Time: 1200331944802 Next To Last Access Time: 1200331985400
2008-01-14 18:33:31,818 DEBUG [http-8080-Processor25] ehcache.Cache (Cache.java:881) - it.inera.icms.db.Asseteditoriale#880 mostRecentTime: 1200331985400
2008-01-14 18:33:31,818 DEBUG [http-8080-Processor25] ehcache.Cache (Cache.java:881) - it.inera.icms.db.Asseteditoriale#880 mostRecentTime: 1200331985400
2008-01-14 18:33:31,818 DEBUG [http-8080-Processor25] ehcache.Cache (Cache.java:882) - it.inera.icms.db.Asseteditoriale#880 Age to Idle: 120000 Age Idled: 26418
2008-01-14 18:33:31,818 DEBUG [http-8080-Processor25] ehcache.Cache (Cache.java:882) - it.inera.icms.db.Asseteditoriale#880 Age to Idle: 120000 Age Idled: 26418
2008-01-14 18:33:31,818 DEBUG [http-8080-Processor25] ehcache.Cache (Cache.java:906) - it.inera.icms.db.Asseteditoriale: Is element with key it.inera.icms.db.Asseteditoriale#880 expired?: false
2008-01-14 18:33:31,818 DEBUG [http-8080-Processor25] ehcache.Cache (Cache.java:906) - it.inera.icms.db.Asseteditoriale: Is element with key it.inera.icms.db.Asseteditoriale#880 expired?: false
2008-01-14 18:33:31,818 DEBUG [http-8080-Processor25] store.MemoryStore (MemoryStore.java:201) - it.inera.icms.db.AsseteditorialeCache: MemoryStore hit for it.inera.icms.db.Asseteditoriale#881
2008-01-14 18:33:31,818 DEBUG [http-8080-Processor25] store.MemoryStore (MemoryStore.java:201) - it.inera.icms.db.AsseteditorialeCache: MemoryStore hit for it.inera.icms.db.Asseteditoriale#881
[...]

Not a single line on "Articolo" being cached. I'm totally stuck here :(


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 28, 2009 2:55 pm 
Newbie

Joined: Mon Feb 18, 2008 7:01 pm
Posts: 5
I had the same problem. I just gave up and cached the base object. I do see a hit for the derived objects.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 28, 2009 2:57 pm 
Newbie

Joined: Mon Feb 18, 2008 7:01 pm
Posts: 5
I had the same problem. I just gave up and cached the base object. I do see a hit for the derived objects.


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