Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » [SOLVED] How to register pre/post refresh callbacks on an entity?(EntityManager refresh callbacks)
icon3.gif  [SOLVED] How to register pre/post refresh callbacks on an entity? [message #879618] Thu, 31 May 2012 14:27 Go to next message
Christophe Bismuth is currently offline Christophe BismuthFriend
Messages: 67
Registered: July 2009
Location: Paris, France
Member

Hi,

Is there any way to register pre/post refresh callbacks on an entity?

I have some business logic to trigger in a setter only upon developer API call, not when the entity is refreshed.

It's all about a computed field which value can be overridden by an end-user input.
The problem is when refreshing the entity, the field is computed again and erase the value overridden by the user input retrieved from the database. And then, the entity is getting dirty just after being refreshed.

Thanks,
Chris

[Updated on: Fri, 01 June 2012 09:00]

Report message to a moderator

Re: How to register pre/post refresh callbacks on an entity? [message #879776 is a reply to message #879618] Thu, 31 May 2012 20:30 Go to previous messageGo to next message
Chris Delahunt is currently offline Chris DelahuntFriend
Messages: 1389
Registered: July 2009
Senior Member
There is the PostLoad event is invoked after the entity is first loaded in or when it gets refreshed. You can specify a method on the entity using the @PostLoad annotation.

I am not sure of your requirement though. Are you saying the business logic is being fired when the entity is getting refreshed? If so, the likely cause is that you have business logic in your getters/setters and are using property access. It is not advisable to have any logic within the methods JPA needs to use to load your entity as it is provider specific on when they get called, and can undesired effects. You might want to use field access so that the accessors can trigger your logic, and the JPA provider touch the fields directly.

Best Regards,
Chris
Re: How to register pre/post refresh callbacks on an entity? [message #879996 is a reply to message #879776] Fri, 01 June 2012 09:00 Go to previous message
Christophe Bismuth is currently offline Christophe BismuthFriend
Messages: 67
Registered: July 2009
Location: Paris, France
Member

Thank you Chris for the hint.

I've switched the entity to field access and it works well. Business logic is triggered from the UI (Vaadin) with setters and not anymore by the entity manager while refreshing.

@Access(AccessType.FIELD)


Thank you,
Christophe
Previous Topic:JPA Error when new entity is added without DropAndCreate
Next Topic:Generate schema from MOXY external bindings-oxm.xml file...
Goto Forum:
  


Current Time: Thu Mar 28 17:12:15 GMT 2024

Powered by FUDForum. Page generated in 0.05335 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top