[
https://issues.apache.org/jira/browse/OPENJPA-1775?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Radu B closed OPENJPA-1775.
---------------------------
Resolution: Not A Problem
Question posted on OpenJPA user and dev forum
> Get original object state for audit purpose
> -------------------------------------------
>
> Key: OPENJPA-1775
> URL: https://issues.apache.org/jira/browse/OPENJPA-1775
> Project: OpenJPA
> Issue Type: Question
> Components: Enhance, kernel
> Affects Versions: 2.0.0
> Environment: GlassFish 3, OpenJpa 2.0
> Reporter: Radu B
>
> I need to get original object state before a merge() is called.
> I tried in my service edit() method, by using :
> public void edit(Customer customer) {
> Customer initialState = null;
> log.info("About to update customer id " + customer.getCustomerId() +
> " with name " + customer.getName());
> PersistenceCapable currentState = (PersistenceCapable)customer;
> try {
> StateManagerImpl sm =
> (StateManagerImpl)currentState.pcGetStateManager();
> SaveFieldManager sfm = sm.getSaveFieldManager();
> PersistenceCapable oldState = sfm.getState();
> initialState = (Customer)oldState;
> log.info("Customer id " + customer.getCustomerId() + " OLD NAME
> WAS " + initialState.getName());
> }
> catch (Exception e) {
> log.severe("Failed to get old object state: " + e.toString());
> }
> getEntityManager().merge(customer);
> }
> I get the error:
> SEVERE: Failed to get old object state: java.lang.ClassCastException:
> org.apache.openjpa.kernel.DetachedStateManager cannot be cast to
> org.apache.openjpa.kernel.StateManagerImpl
> Can you please suggest a way to get the original loaded object?
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.