I am writing a stand-alone add-on module for an application that uses a library with JPA-annotated domain entity objects. The application itself is already in Production, it has been deployed at the customer site, and no libraries should be modified/redeployed. Here's the issue I am facing. My new module has to use the exact same version/instance of the domain library the existing application is using - it is the requirement. However, the existing entity classes (that I cannot touch) have @PrePersist-annotated methods that, unfortunately, do stuff that prevents my module from properly persisting the entities that my process populates. In other words, the existing domain model - unfortunately - was originally hard-wired to work in a particular scenario when the new entities could only be created by one client application, and that scenario required generating and setting certain values on the entities before persisting them. So, that was burnt into the model. Now, there is an urgent requirement to allow other processes to populate and load entities into the system - with those values already set on the entity. For example, normally the @PrePersist-annotated method would generate a new value and set it on a private property. For my application, I need to populate that property via a public setter bypassing the @PrePersist-annotated method. Is it possible to do without extending the class and overriding the method? What if I use an entity interceptor and implement the onSave() method? Would it override the @PrePersist annotation? Or, is it possible to disable/ignore a specific annotation?
Thanks, Alec
|