openjpa-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Kevin Sutter <kwsut...@gmail.com>
Subject Re: [jira] Created: (OPENJPA-1775) Get original object state for audit purpose
Date Thu, 26 Aug 2010 22:30:12 GMT
You should probably post questions like this to the OpenJPA users or dev
forums [1] instead of creating JIRAs.  Thanks.

Kevin

[1]  http://openjpa.apache.org/mailing-lists.html

On Thu, Aug 26, 2010 at 5:10 PM, Radu B (JIRA) <jira@apache.org> wrote:

> 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.
>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message