-->
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.  [ 1 post ] 
Author Message
 Post subject: Change the loaded entity after properties have been injected
PostPosted: Mon Mar 21, 2011 3:21 pm 
Newbie

Joined: Wed May 21, 2008 11:21 am
Posts: 11
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.