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: Multiple caching strategies on the same class/table?
PostPosted: Fri Mar 21, 2008 10:56 pm 
Newbie

Joined: Fri Mar 21, 2008 10:44 pm
Posts: 4
On the website, there will 2 sets of users: admins and users. Admins access the database tables and modify them, while users access the same tables but only read them.

The performance for the "users" is the most critical, therefore we are trying to set caching strategy to "read" for the "users".

However since "admins" need to update the tables, we will need to set 2 different caching strategies on the same tables. What's the best way to achieve this? Should we define 2 sets of identical classes with 2 sets of almost identical mappings except for caching strategy?

Thanks in advance!


Top
 Profile  
 
 Post subject: Not working!
PostPosted: Fri Apr 04, 2008 12:47 pm 
Newbie

Joined: Fri Mar 21, 2008 10:44 pm
Posts: 4
I basically defined one class inherit the other with different caching strategy:

@Entity
@Table(name="MyTable")
@Cache(usage=CacheConcurrencyStrategy.READ_ONLY)
public class BaseClass {
...
}


@Entity
@Cache(usage=CacheConcurrencyStrategy.NONE)
public class ExtendedClass extends BaseClass {
...
}

However the above scheme doesn't seem to work at the runtime. I can create a new ExtendedClass and insert it into DB, but when I modify ExtendedClass and try to update, I get the following exception:

Apr 4, 2008 12:32:53 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet default threw exception
java.lang.UnsupportedOperationException: Can't write to a readonly object
at org.hibernate.cache.ReadOnlyCache.lock(ReadOnlyCache.java:43)
at org.hibernate.action.EntityUpdateAction.execute(EntityUpdateAction.java:85)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:250)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:234)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:142)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:338)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
at org.springframework.orm.hibernate3.HibernateTransactionManager.doCommit(HibernateTransactionManager.java:575)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:662)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:632)
at org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:314)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:117)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:166)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
at $Proxy63.updateExtendedClass(Unknown Source)
at com.myapp.web.SomeAction.save(SomeAction.java:72)

How do I provide different caching strategies to different set of users who use distinct set of pages?

Thank you in advance!


Top
 Profile  
 
 Post subject: One solution
PostPosted: Fri Apr 04, 2008 1:32 pm 
Newbie

Joined: Fri Mar 21, 2008 10:44 pm
Posts: 4
It seems I have to define 2 independent class, one mutable and one not. The mutable one is the writer and the other one can use the read-only cache.

The problem is I have to define everything in 2 classes only so I can use the read-only cache.

This sounds a limitation to me ...


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 09, 2008 10:18 am 
Newbie

Joined: Mon Aug 14, 2006 8:06 pm
Posts: 18
Location: Montréal, Québec
Off the cuff suggestion (not tested).

What if you defined an AbstractBaseClass in which you put all your properties, accessors and methods, and you annotate all of these as you normally would. Also annotate this abstract class with the annotation:
@MappedSuperclass
(Do not use @Entity, here!)

Then, use that AbstractBaseClass as the mother of your other two classes. Those two classes will be empty (unless you wish to add some proprietary stuff in either), and annotate each with the usual:
@Entity etc.

In that setup, you can annotate each real class with its own
@Cache
annotation.

How does that sound?


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.