Quantcast
Channel: Spring Community Forums - Data
Viewing all articles
Browse latest Browse all 297

MongoEventListener, onAfterLoad and @DBRef

$
0
0
Hi,

I'm using spring-core 3.2.3, spring-data-commons 1.5.1 and spring-data-mongodb 1.2.1

I've created an annotation to flag certain fields to be compressed before being persisted to the mongdb repository. This works great for saving objects to the database (both aText and bText are compressed in the database). but I am having some trouble retrieving the proper results from the database.

My data objects look something like this:

Code:

class A {
  @Compress
  private String aText;
 
  @DBRef
  private List<B> listOfB;
}

class B {
  @Compress
  private String bText;
}

I have a class that extends AbstractMongoEventListener and compresses any fields that that are annotated with @Compress during onBeforeSave. This works great and both aText and bText get compressed.

To uncompress the fields I have overloaded onAfterLoad and search for any fields in the DBObject that are annotated with @Compress. This works for the fields of A, but not B when items of class A are retrieved using the repository interface. However, the event listener is not called again when the DBRefs are actually resolved and read from the database, so I'm stuck with an invalid value for bText. Is there anyway to work around this?

Viewing all articles
Browse latest Browse all 297

Trending Articles