You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@struts.apache.org by "Peter Kelley (JIRA)" <ji...@apache.org> on 2009/04/25 05:39:31 UTC

[jira] Updated: (WW-3098) NeedsRefresh not working for ModelDrivenInterceptor and Hibernate

     [ https://issues.apache.org/struts/browse/WW-3098?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Peter Kelley updated WW-3098:
-----------------------------

    Description: 
I have the following configured in struts.xml:

                <interceptor-ref name="modelDriven">
                    <!-- allow actions to change the model during execution so that the view gets a new model. --> 
                    <param name="refreshModelBeforeResult">true</param>
                </interceptor-ref>

and in my action:
    /**
     * Create or update the entity.
     * 
     * @return <code>Show</code>
     */
    public String save() {
        LOG.debug("save() Called");
        setEntity(getDao().save(entity));
        return SHOW;
    }

Where the entity has not previously saved by Hibernate and Hibernate is returning the entity with the id field set.

When struts gets to the following code in ModelDrivenInterceptor (lines 112-117):

            // Check to see if the new model instance is already on the stack
            for (Object item : root) {
                if (item == newModel) {
                    needsRefresh = false;
                }
            }

the test equates to true even though I can see in the debugger that the two objects have different object identities.

Changing line 114 to:

                if (item.equals(newModel)) {

fixes the problem.

I can only think that the cglib enhanced object returned by Hibernate does something weird with == but responds to .equals() correctly.

  was:
I have the following configured in struts.xml:

                <interceptor-ref name="Driven">
                    <!-- allow actions to change the model during execution so that the view gets a new model. --> 
                    <param name="refreshModelBeforeResult">true</param>
                </interceptor-ref>

and in my action:
    /**
     * Create or update the entity.
     * 
     * @return <code>Show</code>
     */
    public String save() {
        LOG.debug("save() Called");
        setEntity(getDao().save(entity));
        return SHOW;
    }

Where the entity has not previously saved by Hibernate and Hibernate is returning the entity with the id field set.

When struts gets to the following code in ModelDrivenInterceptor (lines 112-117):

            // Check to see if the new model instance is already on the stack
            for (Object item : root) {
                if (item == newModel) {
                    needsRefresh = false;
                }
            }

the test equates to true even though I can see in the debugger that the two objects have different object identities.

Changing line 114 to:

                if (item.equals(newModel)) {

fixes the problem.

I can only think that the cglib enhanced object returned by Hibernate does something weird with == but responds to .equals() correctly.


> NeedsRefresh not working for ModelDrivenInterceptor and Hibernate
> -----------------------------------------------------------------
>
>                 Key: WW-3098
>                 URL: https://issues.apache.org/struts/browse/WW-3098
>             Project: Struts 2
>          Issue Type: Bug
>          Components: Core Interceptors
>    Affects Versions: 2.1.6
>         Environment: Hibernate
> JPA
> Windows XP
> Tomcat 6 running under Eclipse 3.4
> Java 1.6 with Java 1.5 source compliance
>            Reporter: Peter Kelley
>
> I have the following configured in struts.xml:
>                 <interceptor-ref name="modelDriven">
>                     <!-- allow actions to change the model during execution so that the view gets a new model. --> 
>                     <param name="refreshModelBeforeResult">true</param>
>                 </interceptor-ref>
> and in my action:
>     /**
>      * Create or update the entity.
>      * 
>      * @return <code>Show</code>
>      */
>     public String save() {
>         LOG.debug("save() Called");
>         setEntity(getDao().save(entity));
>         return SHOW;
>     }
> Where the entity has not previously saved by Hibernate and Hibernate is returning the entity with the id field set.
> When struts gets to the following code in ModelDrivenInterceptor (lines 112-117):
>             // Check to see if the new model instance is already on the stack
>             for (Object item : root) {
>                 if (item == newModel) {
>                     needsRefresh = false;
>                 }
>             }
> the test equates to true even though I can see in the debugger that the two objects have different object identities.
> Changing line 114 to:
>                 if (item.equals(newModel)) {
> fixes the problem.
> I can only think that the cglib enhanced object returned by Hibernate does something weird with == but responds to .equals() correctly.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.