Quantcast
Channel: Spring Community Forums - NoSQL
Viewing all articles
Browse latest Browse all 128

Trying to do a TTL with MongoDB in spring, getting can't serialize class error

$
0
0
Hi,
I am trying to do cache abstraction with custom annotations using MongoDB.
I used Spring AOP @Pointcut("execution(@MyCacheable annotation...
I am trying to set TTL while putting the values into cache.

DBCollection collection = mongoTemplate.getCollection(name);
// TTL Index
BasicDBObject index = new BasicDBObject(key.toString(), value);
BasicDBObject options = new BasicDBObject("expireAfterSeconds", TimeUnit.MINUTES.toSeconds(1));
collection.ensureIndex(index, options);


At collection.ensureIndex i amgetting can't serialize class exception
My value object is Serialized and having versionId also.

Stacktrace
java.lang.IllegalArgumentException: can't serialize class caching.springaop.model.Employee
at org.bson.BasicBSONEncoder._putObjectField(BasicBSO NEncoder.java:270)
at org.bson.BasicBSONEncoder.putObject(BasicBSONEncod er.java:174)
at org.bson.BasicBSONEncoder._putObjectField(BasicBSO NEncoder.java:226)
at org.bson.BasicBSONEncoder.putObject(BasicBSONEncod er.java:174)
at org.bson.BasicBSONEncoder.putObject(BasicBSONEncod er.java:120)
at com.mongodb.DefaultDBEncoder.writeObject(DefaultDB Encoder.java:27)


Can anyone help me on this.


thanks in advance
Bhaskar

Viewing all articles
Browse latest Browse all 128

Trending Articles