After loading an entity (via load or find), just before the response is returned, i'd like to change the entity (the actual reference). Does anyone know how to do this?
The reason is that the entity into which the properties were injected during load is a builder object.
I tried to use a PostLoadEventListener like this:
Code:
public void onPostLoad(PostLoadEvent event) {
Object entity = event.getEntity();
if(null != entity && entity instanceof MyBuilder){
MyBuilder builder = (MyBuilder)entity;
MyActualClass result = builder.build();
event.setEntity(result);
}
}
but it seems that whatever I set in that event is ignored and lost (makes sense, this is how events work).
The only option that seems to be left is overriding an EntityPersister but that's so yucky!
Do you know of another, more elegant solution?
Thanks!
Cristian