jakarta-jcs-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Pooja <pooja...@gmail.com>
Subject Re: ClassCastException for non-wrapper Object Keys
Date Mon, 12 Jun 2006 16:16:57 GMT
Thanks Aaron,Niall and Alistair. The problem was that of my key not
implementing Serializable. Works well now. Thank you.

To answer the questions about environment, so that the solution goes
complete in the archives: I am not using RemoteCache, just normal LRU
implementation example from the site. I am deploying the whole thing as a
war and jcs jar is available only in my /WEB-INF/lib.

Not really complaining, but if it has already not brought into notice, the
mail archives email ID at this page<http://jakarta.apache.org/site/mail2.html>(
http://jakarta.apache.org/site/mail2.html) is incorrect. As that is the
first site that comes when you google for <apache JCS forum>, may be we can
change it. [I got the right ID by trying this one first and then clicking on
the third link on the second page and going through to the list index]

Regards
--- Pooja.

On 6/12/06, Niall Gallagher <niall@switchfire.com> wrote:
>
> Hi Aaron,
>
> You could change the signature of put() methods...
>
> public void put(Object name, Object obj)
> to
> public void put(Serializable name, Serializable obj)
>
> That way only objects implementing the Serializable interface could be
> cached. It would not account for non-serializable objects referenced by
> the main object however and it might not look user-friendly to
> developers unfamiliar with serialization.
>
> On Mon, 2006-06-12 at 07:00 -0700, Aaron Smuts wrote:
>
> > Your keys and values must be serializable.  Although
> > the JCS api suggests that you can cache any object,
> > you must only cache serializable objects.  This is a
> > known issue with no good solution.
> >
> > --- Pooja <poojac20@gmail.com> wrote:
> >
> > > Hi
> > >
> > > I've configured my cache using the default values
> > > from apache site. The
> > > cache is being configured, I confirmed cuz it gets
> > > the name I speicifed in
> > > cache.ccf.
> > >
> > > Now, if I try to put a Long, String or other wrapper
> > > objects as keys,
> > > everything works fine. But the moment I supply my
> > > own object as key, I get
> > > CacheException (with no further cause or explanation
> > > below it) - Exception
> > > trace attached at the end.
> > >
> > > Also, from the empty cache if I try to get an object
> > > (I expect null) with my
> > > key, I get a ClassCastException! - Again, if I try
> > > to get using Long, String
> > > etc, it returns null all right.
> > >
> > > The custom object which I am using as key contained
> > > a long field and an enum
> > > field. I changed it to long and int as an
> > > experiment, but the result was the
> > > same. Is there some place I need to also tell the
> > > cache about the type of
> > > the keys I'll be storing? Is enum a problem? I
> > > gathered from the site and
> > > from the signature of put() and get() that it can be
> > > any Object.
> > >
> > > I am hoping there is some simple explanation for
> > > this behavior which I don't
> > > know. Will be glad for any light.
> > >
> > > PS: Classpath is not a problem, I confirmed by
> > > instantiating a key object
> > > above the get and it happens all right.
> > >
> > > Thanks
> > > --- Pooja.
> > > Exception Trace for CacheException while putting my
> > > own object as key:
> > > org.apache.jcs.access.exception.CacheException:
> > > com.anduril.ring.promos.PromotionKey
> > > org.apache.jcs.access.exception.CacheException:
> > > com.anduril.ring.promos.PromotionKey
> > >     at
> > >
> > org.apache.jcs.access.CacheAccess.put(CacheAccess.java:300)
> > >     at
> > >
> > org.apache.jcs.access.CacheAccess.put(CacheAccess.java:266)
> > > ..... no further causes given
> > > +++++++++++++++++++++++++++++
> > > Exception Trace for ClassCastException while getting
> > > with my own object as
> > > key:
> > > java.lang.ClassCastException:
> > > com.anduril.ring.promos.PromotionKey
> > >     at
> > >
> > org.apache.jcs.access.CacheAccess.get(CacheAccess.java:201)
> > >     at
> > >
> > com.anduril.ring.promocache.PromoCacheJCS.getPromoMessage(Unknown
> > > Source)
> > >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: jcs-users-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: jcs-users-help@jakarta.apache.org
> >
>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message