You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Márcio Gurgel <ma...@gmail.com> on 2008/05/29 07:25:59 UTC

Struts 2 + Hibernate question

Hi all!

I'm using struts 2 + hibernate.
I've a strange problem, if someone could give me a hand I'll be so tankfull.

If I persist a object in my app every things go well and all relationchips
are stored correctey correctly.
The problem occours when I update this object... After the update all data
are stored correctly too, but the problem is that my page shows the old
object (different from database).

This could be some kind of cash from struts 2? Or my problem is just
hibernate?

I tryed this methods to force a refresh after bring the object from database
session.refresh(obj)
session.flush()

Tank so much for attention!

Márcio Gurgel

Re: Struts 2 + Hibernate question

Posted by Márcio Gurgel <ma...@gmail.com>.
Hi!

Tanks Stewart and Owen!

Stewart, I tried by unit test case, and everything went well.
I guess that you discovered the reason of the problem (:

As you saw, after update I call another action (redirect) to show the data.
Now I tried to return a JSP as result, and the problem went away.
In fact the value stack from struts 2 are getting the old object state. But
I need to use redirectAction. Do you have any idea?

You made some questions here are the answers (:

"are both actions still on the stack, or just the last one to run?"
- Honestly I dont know...

"One question - how are you committing your database changes?"
- Every database operation to update a object is inside a session.begin()
and after session.commit() and session.flush()

Could the commit not be happening until after you try to get the updated
object? You mentioned doing a refresh and flush - shouldn't you do a flush
and commit first, and then the refresh?
- By debugging, I sow that after the update the comit() method is aways
called.
I also tried to flush the session before bringing the object from database,
no success too.


Thanks so much for your help and atention.

Márcio Gurgel


2008/5/30 Owen Berry <ow...@gmail.com>:

> If you get Hibernate to log your queries, you can watch your log file and
> make sure that Hibernate is actually executing a select statement when you
> hit that page. If it's not, then it's definitely not Hibernate.
>
> On Thu, May 29, 2008 at 1:25 AM, Márcio Gurgel <ma...@gmail.com>
> wrote:
>
> > Hi all!
> >
> > I'm using struts 2 + hibernate.
> > I've a strange problem, if someone could give me a hand I'll be so
> > tankfull.
> >
> > If I persist a object in my app every things go well and all
> relationchips
> > are stored correctey correctly.
> > The problem occours when I update this object... After the update all
> data
> > are stored correctly too, but the problem is that my page shows the old
> > object (different from database).
> >
> > This could be some kind of cash from struts 2? Or my problem is just
> > hibernate?
> >
> > I tryed this methods to force a refresh after bring the object from
> > database
> > session.refresh(obj)
> > session.flush()
> >
> > Tank so much for attention!
> >
> > Márcio Gurgel
> >
>

Re: Struts 2 + Hibernate question

Posted by Owen Berry <ow...@gmail.com>.
If you get Hibernate to log your queries, you can watch your log file and
make sure that Hibernate is actually executing a select statement when you
hit that page. If it's not, then it's definitely not Hibernate.

On Thu, May 29, 2008 at 1:25 AM, Márcio Gurgel <ma...@gmail.com> wrote:

> Hi all!
>
> I'm using struts 2 + hibernate.
> I've a strange problem, if someone could give me a hand I'll be so
> tankfull.
>
> If I persist a object in my app every things go well and all relationchips
> are stored correctey correctly.
> The problem occours when I update this object... After the update all data
> are stored correctly too, but the problem is that my page shows the old
> object (different from database).
>
> This could be some kind of cash from struts 2? Or my problem is just
> hibernate?
>
> I tryed this methods to force a refresh after bring the object from
> database
> session.refresh(obj)
> session.flush()
>
> Tank so much for attention!
>
> Márcio Gurgel
>

Re: Struts 2 + Hibernate question

Posted by Márcio Gurgel <ma...@gmail.com>.
Hi,

Tanks for your response.
I used to run it on Mozilla, now I tryied in IE 7 but the problem persists.
By debug I saw that the object is coming with the old state.

Sorry about writing "cash"... I also have to improve my english.

Regards!

Márcio Gurgel

2008/5/29 Al Sutton <al...@alsutton.com>:

> Are you sure the page isn't being cached by your browser? Try hitting
> reload (or CTRL + Reload if you're using IE).
>
> Al.
>
>
> Márcio Gurgel wrote:
>
>> Hi all!
>>
>> I'm using struts 2 + hibernate.
>> I've a strange problem, if someone could give me a hand I'll be so
>> tankfull.
>>
>> If I persist a object in my app every things go well and all relationchips
>> are stored correctey correctly.
>> The problem occours when I update this object... After the update all data
>> are stored correctly too, but the problem is that my page shows the old
>> object (different from database).
>>
>> This could be some kind of cash from struts 2? Or my problem is just
>> hibernate?
>>
>> I tryed this methods to force a refresh after bring the object from
>> database
>> session.refresh(obj)
>> session.flush()
>>
>> Tank so much for attention!
>>
>> Márcio Gurgel
>>
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

Re: Struts 2 + Hibernate question

Posted by Al Sutton <al...@alsutton.com>.
Are you sure the page isn't being cached by your browser? Try hitting 
reload (or CTRL + Reload if you're using IE).

Al.

Márcio Gurgel wrote:
> Hi all!
>
> I'm using struts 2 + hibernate.
> I've a strange problem, if someone could give me a hand I'll be so tankfull.
>
> If I persist a object in my app every things go well and all relationchips
> are stored correctey correctly.
> The problem occours when I update this object... After the update all data
> are stored correctly too, but the problem is that my page shows the old
> object (different from database).
>
> This could be some kind of cash from struts 2? Or my problem is just
> hibernate?
>
> I tryed this methods to force a refresh after bring the object from database
> session.refresh(obj)
> session.flush()
>
> Tank so much for attention!
>
> Márcio Gurgel
>
>   

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Struts 2 + Hibernate question

Posted by Stewart Buskirk <st...@owd.com>.
It's probably not hibernate - but you should test that. You could  
write a unit test to test the actions, or just a log statement in the  
update action to check the values of the retrieved object *in the  
context of the action* when it is retrieved.

Maybe the valuestack has the old object in it. I'm not sure how the  
valuestack behaves through a redirectAction result type - are both  
actions still on the stack, or just the last one to run? You could  
test by changing the redirectAction result to an actual redirect sent  
back to the browser. If you have the same problem after doing that,  
the issue is with the Hibernate code or cache, but if the problem goes  
away with a browser redirect, the problem is in the valuestack storing  
the old Hibernate object.

One question - how are you committing your database changes? Could the  
commit not be happening until after you try to get the updated object?  
You mentioned doing a refresh and flush - shouldn't you do a flush and  
commit first, and then the refresh?

The key is the redirectAction - either you are seeing the old object  
in the second action because your changes are not actually committed  
yet, or the valuestack needs to be examined closely to see what it  
contains.


On May 29, 2008, at 11:10 PM, Márcio Gurgel wrote:

> Sure, the updated values are not displayed in <s:property />. But  
> the data
> is not erased, all updated values are ok at my database, it just  
> doesnt
> appear at my jsp. Seems that the database content was disregard.
> My findById method returns a old object /:
>
> If you need I can translate the code.
> I'm already so thankfull !
>
>
>
> 2008/5/30 dusty <du...@yahoo.com>:
>
>>
>> hmmm....I am having trouble with the non-english code.  ;-)
>>
>> Lets try this another way.  When you say old, what do you mean.   
>> The new
>> values that saved for the object are not displaying in  
>> <s:property .../>
>> tags?  The relationships are missing?  Data is erased?
>>
>> -D
>>
>>
>>
>> Márcio Gurgel wrote:
>>>
>>> Hi!
>>>
>>> The result is a redirect.
>>> Thanks a lot for your attention.
>>>
>>> Follow the codes:
>>>
>>> *** STRUTS.XML *** Redirect
>>> <action name="alterarFsc" method="alterarFsc"
>>> class="br.com.sgvdba.actions.cliente.ClienteAction">
>>>                <result name="success" type="redirectAction">
>>>                    ${clienteFsc.cd}
>>>                    abrirPageFsc
>>>                    /cliente
>>>                </result>
>>>                <result type="tiles"
>>> name="input">default.clienteFsc</result>
>>>            </action>
>>>
>>> *** ACTION - UPDATE ***
>>> public String alterarFsc(){
>>>        try {
>>>            String[] telefones = new String[]{telefone1, telefone2,
>>> telefone3, telefone4};
>>>            Integer[] cdsTipTel = new Integer[]{cdTipoTelefone1,
>>> cdTipoTelefone2, cdTipoTelefone3, cdTipoTelefone4};
>>>            getClienteFacade().alterarFsc(clienteFsc,  
>>> getUsuarioLogado(),
>>> cdSitCliente, telefones, cdsTipTel, cdCidadeKey);
>>>            cdClienteFsc = clienteFsc.getCd();
>>>        } catch (Exception e) {
>>>            addActionError(SgvdbaConstants.ERRO_DEFAULT +
>> e.getMessage());
>>>            return Action.INPUT;
>>>        }
>>>        return Action.SUCCESS;
>>>    }
>>>
>>> *** STRUTS.XML - REDIRECTED ACTION ***
>>> <action name="abrirPageFsc" method="abrirPageFsc"
>>> class="br.com.sgvdba.actions.cliente.ClienteAction">
>>>                <result type="tiles"
>>> name="success">default.clienteFsc</result>
>>>                <result type="tiles"
>>> name="input">default.clienteFsc</result>
>>>            </action>
>>>
>>> *** ACTION - A OPEN DATA METHOD ***
>>>    public String abrirPageFsc(){
>>>        try {
>>>            if (clienteFsc != null){
>>>                if (clienteFsc.getCd() != null){
>>>
>>>
>>>                    // ------> Here's comming the old object
>>>                    clienteFsc =
>>> getClienteFacade().recuperarFscPorId(clienteFsc.getCd());
>>>
>>>
>>>
>>> clienteFsc.setCep(MaskUtil.maskCep(clienteFsc.getCep()));
>>>
>>> clienteFsc.setCpf(MaskUtil.maskCpf(clienteFsc.getCpf()));
>>>                     
>>> setQtdTelefones(clienteFsc.getTelefones().size());
>>>
>>>                    int i = 0;
>>>                    List<Telefone> telefoneList =
>>> getTelefoneFacade().recuperarPorCliente(clienteFsc.getCd());
>>>                    for (Iterator<Telefone> it =  
>>> telefoneList.iterator();
>>> it.hasNext();){
>>>                        Telefone telefone = (Telefone) it.next();
>>>                        switch (i) {
>>>                        case 0:
>>>                            telefone1 =
>>> MaskUtil.maskTelefone(telefone.getNumTel());
>>>                            valueTipoTelefone1 =
>>> telefone.getTipoTelefone().getCd();
>>>                            break;
>>>                        case 1:
>>>                            telefone2 =
>>> MaskUtil.maskTelefone(telefone.getNumTel());
>>>                            valueTipoTelefone2 =
>>> telefone.getTipoTelefone().getCd();
>>>                            break;
>>>                        case 2:
>>>                            telefone3 =
>>> MaskUtil.maskTelefone(telefone.getNumTel());
>>>                            valueTipoTelefone3 =
>>> telefone.getTipoTelefone().getCd();
>>>                            break;
>>>                        case 3:
>>>                            telefone4 =
>>> MaskUtil.maskTelefone(telefone.getNumTel());
>>>                            valueTipoTelefone4 =
>>> telefone.getTipoTelefone().getCd();
>>>                            break;
>>>                        }
>>>                        i++;
>>>                    }
>>>                }
>>>
>>>            }
>>>
>>>        } catch (Exception e) {
>>>            addActionError(SgvdbaConstants.ERRO_DEFAULT +
>> e.getMessage());
>>>        }
>>>        return Action.SUCCESS;
>>>    }
>>>
>>>
>>>
>>> 2008/5/30 dusty <du...@yahoo.com>:
>>>
>>>>
>>>> What is the result of the post action?  A redirect?  JSP?
>>>>
>>>> Its probably best to post some of the relevant action code and
>> struts.xml
>>>> first, and then if we need to we can go into the Hibernate code.
>>>>
>>>> -D
>>>>
>>>> Márcio Gurgel wrote:
>>>>>
>>>>> Hi all!
>>>>>
>>>>> I'm using struts 2 + hibernate.
>>>>> I've a strange problem, if someone could give me a hand I'll be so
>>>>> tankfull.
>>>>>
>>>>> If I persist a object in my app every things go well and all
>>>> relationchips
>>>>> are stored correctey correctly.
>>>>> The problem occours when I update this object... After the  
>>>>> update all
>>>> data
>>>>> are stored correctly too, but the problem is that my page shows  
>>>>> the
>> old
>>>>> object (different from database).
>>>>>
>>>>> This could be some kind of cash from struts 2? Or my problem is  
>>>>> just
>>>>> hibernate?
>>>>>
>>>>> I tryed this methods to force a refresh after bring the object  
>>>>> from
>>>>> database
>>>>> session.refresh(obj)
>>>>> session.flush()
>>>>>
>>>>> Tank so much for attention!
>>>>>
>>>>> Márcio Gurgel
>>>>>
>>>>>
>>>>
>>>> --
>>>> View this message in context:
>>>>
>> http://www.nabble.com/Struts-2-%2B-Hibernate-question-tp17527841p17550934.html
>>>> Sent from the Struts - User mailing list archive at Nabble.com.
>>>>
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>>>> For additional commands, e-mail: user-help@struts.apache.org
>>>>
>>>>
>>>
>>>
>>
>> --
>> View this message in context:
>> http://www.nabble.com/Struts-2-%2B-Hibernate-question-tp17527841p17551202.html
>> Sent from the Struts - User mailing list archive at Nabble.com.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Struts 2 + Hibernate question

Posted by Márcio Gurgel <ma...@gmail.com>.
Sure, the updated values are not displayed in <s:property />. But the data
is not erased, all updated values are ok at my database, it just doesnt
appear at my jsp. Seems that the database content was disregard.
My findById method returns a old object /:

If you need I can translate the code.
I'm already so thankfull !



2008/5/30 dusty <du...@yahoo.com>:

>
> hmmm....I am having trouble with the non-english code.  ;-)
>
> Lets try this another way.  When you say old, what do you mean.  The new
> values that saved for the object are not displaying in <s:property .../>
> tags?  The relationships are missing?  Data is erased?
>
> -D
>
>
>
> Márcio Gurgel wrote:
> >
> > Hi!
> >
> > The result is a redirect.
> > Thanks a lot for your attention.
> >
> > Follow the codes:
> >
> > *** STRUTS.XML *** Redirect
> > <action name="alterarFsc" method="alterarFsc"
> > class="br.com.sgvdba.actions.cliente.ClienteAction">
> >                 <result name="success" type="redirectAction">
> >                     ${clienteFsc.cd}
> >                     abrirPageFsc
> >                     /cliente
> >                 </result>
> >                 <result type="tiles"
> > name="input">default.clienteFsc</result>
> >             </action>
> >
> > *** ACTION - UPDATE ***
> > public String alterarFsc(){
> >         try {
> >             String[] telefones = new String[]{telefone1, telefone2,
> > telefone3, telefone4};
> >             Integer[] cdsTipTel = new Integer[]{cdTipoTelefone1,
> > cdTipoTelefone2, cdTipoTelefone3, cdTipoTelefone4};
> >             getClienteFacade().alterarFsc(clienteFsc, getUsuarioLogado(),
> > cdSitCliente, telefones, cdsTipTel, cdCidadeKey);
> >             cdClienteFsc = clienteFsc.getCd();
> >         } catch (Exception e) {
> >             addActionError(SgvdbaConstants.ERRO_DEFAULT +
> e.getMessage());
> >             return Action.INPUT;
> >         }
> >         return Action.SUCCESS;
> >     }
> >
> > *** STRUTS.XML - REDIRECTED ACTION ***
> > <action name="abrirPageFsc" method="abrirPageFsc"
> > class="br.com.sgvdba.actions.cliente.ClienteAction">
> >                 <result type="tiles"
> > name="success">default.clienteFsc</result>
> >                 <result type="tiles"
> > name="input">default.clienteFsc</result>
> >             </action>
> >
> > *** ACTION - A OPEN DATA METHOD ***
> >     public String abrirPageFsc(){
> >         try {
> >             if (clienteFsc != null){
> >                 if (clienteFsc.getCd() != null){
> >
> >
> >                     // ------> Here's comming the old object
> >                     clienteFsc =
> > getClienteFacade().recuperarFscPorId(clienteFsc.getCd());
> >
> >
> >
> > clienteFsc.setCep(MaskUtil.maskCep(clienteFsc.getCep()));
> >
> > clienteFsc.setCpf(MaskUtil.maskCpf(clienteFsc.getCpf()));
> >                     setQtdTelefones(clienteFsc.getTelefones().size());
> >
> >                     int i = 0;
> >                     List<Telefone> telefoneList =
> > getTelefoneFacade().recuperarPorCliente(clienteFsc.getCd());
> >                     for (Iterator<Telefone> it = telefoneList.iterator();
> > it.hasNext();){
> >                         Telefone telefone = (Telefone) it.next();
> >                         switch (i) {
> >                         case 0:
> >                             telefone1 =
> > MaskUtil.maskTelefone(telefone.getNumTel());
> >                             valueTipoTelefone1 =
> > telefone.getTipoTelefone().getCd();
> >                             break;
> >                         case 1:
> >                             telefone2 =
> > MaskUtil.maskTelefone(telefone.getNumTel());
> >                             valueTipoTelefone2 =
> > telefone.getTipoTelefone().getCd();
> >                             break;
> >                         case 2:
> >                             telefone3 =
> > MaskUtil.maskTelefone(telefone.getNumTel());
> >                             valueTipoTelefone3 =
> > telefone.getTipoTelefone().getCd();
> >                             break;
> >                         case 3:
> >                             telefone4 =
> > MaskUtil.maskTelefone(telefone.getNumTel());
> >                             valueTipoTelefone4 =
> > telefone.getTipoTelefone().getCd();
> >                             break;
> >                         }
> >                         i++;
> >                     }
> >                 }
> >
> >             }
> >
> >         } catch (Exception e) {
> >             addActionError(SgvdbaConstants.ERRO_DEFAULT +
> e.getMessage());
> >         }
> >         return Action.SUCCESS;
> >     }
> >
> >
> >
> > 2008/5/30 dusty <du...@yahoo.com>:
> >
> >>
> >> What is the result of the post action?  A redirect?  JSP?
> >>
> >> Its probably best to post some of the relevant action code and
> struts.xml
> >> first, and then if we need to we can go into the Hibernate code.
> >>
> >> -D
> >>
> >> Márcio Gurgel wrote:
> >> >
> >> > Hi all!
> >> >
> >> > I'm using struts 2 + hibernate.
> >> > I've a strange problem, if someone could give me a hand I'll be so
> >> > tankfull.
> >> >
> >> > If I persist a object in my app every things go well and all
> >> relationchips
> >> > are stored correctey correctly.
> >> > The problem occours when I update this object... After the update all
> >> data
> >> > are stored correctly too, but the problem is that my page shows the
> old
> >> > object (different from database).
> >> >
> >> > This could be some kind of cash from struts 2? Or my problem is just
> >> > hibernate?
> >> >
> >> > I tryed this methods to force a refresh after bring the object from
> >> > database
> >> > session.refresh(obj)
> >> > session.flush()
> >> >
> >> > Tank so much for attention!
> >> >
> >> > Márcio Gurgel
> >> >
> >> >
> >>
> >> --
> >> View this message in context:
> >>
> http://www.nabble.com/Struts-2-%2B-Hibernate-question-tp17527841p17550934.html
> >> Sent from the Struts - User mailing list archive at Nabble.com.
> >>
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> >> For additional commands, e-mail: user-help@struts.apache.org
> >>
> >>
> >
> >
>
> --
> View this message in context:
> http://www.nabble.com/Struts-2-%2B-Hibernate-question-tp17527841p17551202.html
> Sent from the Struts - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

Re: Struts 2 + Hibernate question

Posted by dusty <du...@yahoo.com>.
hmmm....I am having trouble with the non-english code.  ;-)

Lets try this another way.  When you say old, what do you mean.  The new
values that saved for the object are not displaying in <s:property .../>
tags?  The relationships are missing?  Data is erased? 

-D



Márcio Gurgel wrote:
> 
> Hi!
> 
> The result is a redirect.
> Thanks a lot for your attention.
> 
> Follow the codes:
> 
> *** STRUTS.XML *** Redirect
> <action name="alterarFsc" method="alterarFsc"
> class="br.com.sgvdba.actions.cliente.ClienteAction">
>                 <result name="success" type="redirectAction">
>                     ${clienteFsc.cd}
>                     abrirPageFsc
>                     /cliente
>                 </result>
>                 <result type="tiles"
> name="input">default.clienteFsc</result>
>             </action>
> 
> *** ACTION - UPDATE ***
> public String alterarFsc(){
>         try {
>             String[] telefones = new String[]{telefone1, telefone2,
> telefone3, telefone4};
>             Integer[] cdsTipTel = new Integer[]{cdTipoTelefone1,
> cdTipoTelefone2, cdTipoTelefone3, cdTipoTelefone4};
>             getClienteFacade().alterarFsc(clienteFsc, getUsuarioLogado(),
> cdSitCliente, telefones, cdsTipTel, cdCidadeKey);
>             cdClienteFsc = clienteFsc.getCd();
>         } catch (Exception e) {
>             addActionError(SgvdbaConstants.ERRO_DEFAULT + e.getMessage());
>             return Action.INPUT;
>         }
>         return Action.SUCCESS;
>     }
> 
> *** STRUTS.XML - REDIRECTED ACTION ***
> <action name="abrirPageFsc" method="abrirPageFsc"
> class="br.com.sgvdba.actions.cliente.ClienteAction">
>                 <result type="tiles"
> name="success">default.clienteFsc</result>
>                 <result type="tiles"
> name="input">default.clienteFsc</result>
>             </action>
> 
> *** ACTION - A OPEN DATA METHOD ***
>     public String abrirPageFsc(){
>         try {
>             if (clienteFsc != null){
>                 if (clienteFsc.getCd() != null){
> 
> 
>                     // ------> Here's comming the old object
>                     clienteFsc =
> getClienteFacade().recuperarFscPorId(clienteFsc.getCd());
> 
> 
> 
> clienteFsc.setCep(MaskUtil.maskCep(clienteFsc.getCep()));
> 
> clienteFsc.setCpf(MaskUtil.maskCpf(clienteFsc.getCpf()));
>                     setQtdTelefones(clienteFsc.getTelefones().size());
> 
>                     int i = 0;
>                     List<Telefone> telefoneList =
> getTelefoneFacade().recuperarPorCliente(clienteFsc.getCd());
>                     for (Iterator<Telefone> it = telefoneList.iterator();
> it.hasNext();){
>                         Telefone telefone = (Telefone) it.next();
>                         switch (i) {
>                         case 0:
>                             telefone1 =
> MaskUtil.maskTelefone(telefone.getNumTel());
>                             valueTipoTelefone1 =
> telefone.getTipoTelefone().getCd();
>                             break;
>                         case 1:
>                             telefone2 =
> MaskUtil.maskTelefone(telefone.getNumTel());
>                             valueTipoTelefone2 =
> telefone.getTipoTelefone().getCd();
>                             break;
>                         case 2:
>                             telefone3 =
> MaskUtil.maskTelefone(telefone.getNumTel());
>                             valueTipoTelefone3 =
> telefone.getTipoTelefone().getCd();
>                             break;
>                         case 3:
>                             telefone4 =
> MaskUtil.maskTelefone(telefone.getNumTel());
>                             valueTipoTelefone4 =
> telefone.getTipoTelefone().getCd();
>                             break;
>                         }
>                         i++;
>                     }
>                 }
> 
>             }
> 
>         } catch (Exception e) {
>             addActionError(SgvdbaConstants.ERRO_DEFAULT + e.getMessage());
>         }
>         return Action.SUCCESS;
>     }
> 
> 
> 
> 2008/5/30 dusty <du...@yahoo.com>:
> 
>>
>> What is the result of the post action?  A redirect?  JSP?
>>
>> Its probably best to post some of the relevant action code and struts.xml
>> first, and then if we need to we can go into the Hibernate code.
>>
>> -D
>>
>> Márcio Gurgel wrote:
>> >
>> > Hi all!
>> >
>> > I'm using struts 2 + hibernate.
>> > I've a strange problem, if someone could give me a hand I'll be so
>> > tankfull.
>> >
>> > If I persist a object in my app every things go well and all
>> relationchips
>> > are stored correctey correctly.
>> > The problem occours when I update this object... After the update all
>> data
>> > are stored correctly too, but the problem is that my page shows the old
>> > object (different from database).
>> >
>> > This could be some kind of cash from struts 2? Or my problem is just
>> > hibernate?
>> >
>> > I tryed this methods to force a refresh after bring the object from
>> > database
>> > session.refresh(obj)
>> > session.flush()
>> >
>> > Tank so much for attention!
>> >
>> > Márcio Gurgel
>> >
>> >
>>
>> --
>> View this message in context:
>> http://www.nabble.com/Struts-2-%2B-Hibernate-question-tp17527841p17550934.html
>> Sent from the Struts - User mailing list archive at Nabble.com.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
> 
> 

-- 
View this message in context: http://www.nabble.com/Struts-2-%2B-Hibernate-question-tp17527841p17551202.html
Sent from the Struts - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Struts 2 + Hibernate question

Posted by Márcio Gurgel <ma...@gmail.com>.
Hi!

The result is a redirect.
Thanks a lot for your attention.

Follow the codes:

*** STRUTS.XML *** Redirect
<action name="alterarFsc" method="alterarFsc"
class="br.com.sgvdba.actions.cliente.ClienteAction">
                <result name="success" type="redirectAction">
                    <param name="clienteFsc.cd">${clienteFsc.cd}</param>
                    <param name="actionName">abrirPageFsc</param>
                    <param name="namespace">/cliente</param>
                </result>
                <result type="tiles"
name="input">default.clienteFsc</result>
            </action>

*** ACTION - UPDATE ***
public String alterarFsc(){
        try {
            String[] telefones = new String[]{telefone1, telefone2,
telefone3, telefone4};
            Integer[] cdsTipTel = new Integer[]{cdTipoTelefone1,
cdTipoTelefone2, cdTipoTelefone3, cdTipoTelefone4};
            getClienteFacade().alterarFsc(clienteFsc, getUsuarioLogado(),
cdSitCliente, telefones, cdsTipTel, cdCidadeKey);
            cdClienteFsc = clienteFsc.getCd();
        } catch (Exception e) {
            addActionError(SgvdbaConstants.ERRO_DEFAULT + e.getMessage());
            return Action.INPUT;
        }
        return Action.SUCCESS;
    }

*** STRUTS.XML - REDIRECTED ACTION ***
<action name="abrirPageFsc" method="abrirPageFsc"
class="br.com.sgvdba.actions.cliente.ClienteAction">
                <result type="tiles"
name="success">default.clienteFsc</result>
                <result type="tiles"
name="input">default.clienteFsc</result>
            </action>

*** ACTION - A OPEN DATA METHOD ***
    public String abrirPageFsc(){
        try {
            if (clienteFsc != null){
                if (clienteFsc.getCd() != null){


                    // ------> Here's comming the old object
                    clienteFsc =
getClienteFacade().recuperarFscPorId(clienteFsc.getCd());



clienteFsc.setCep(MaskUtil.maskCep(clienteFsc.getCep()));

clienteFsc.setCpf(MaskUtil.maskCpf(clienteFsc.getCpf()));
                    setQtdTelefones(clienteFsc.getTelefones().size());

                    int i = 0;
                    List<Telefone> telefoneList =
getTelefoneFacade().recuperarPorCliente(clienteFsc.getCd());
                    for (Iterator<Telefone> it = telefoneList.iterator();
it.hasNext();){
                        Telefone telefone = (Telefone) it.next();
                        switch (i) {
                        case 0:
                            telefone1 =
MaskUtil.maskTelefone(telefone.getNumTel());
                            valueTipoTelefone1 =
telefone.getTipoTelefone().getCd();
                            break;
                        case 1:
                            telefone2 =
MaskUtil.maskTelefone(telefone.getNumTel());
                            valueTipoTelefone2 =
telefone.getTipoTelefone().getCd();
                            break;
                        case 2:
                            telefone3 =
MaskUtil.maskTelefone(telefone.getNumTel());
                            valueTipoTelefone3 =
telefone.getTipoTelefone().getCd();
                            break;
                        case 3:
                            telefone4 =
MaskUtil.maskTelefone(telefone.getNumTel());
                            valueTipoTelefone4 =
telefone.getTipoTelefone().getCd();
                            break;
                        }
                        i++;
                    }
                }

            }

        } catch (Exception e) {
            addActionError(SgvdbaConstants.ERRO_DEFAULT + e.getMessage());
        }
        return Action.SUCCESS;
    }



2008/5/30 dusty <du...@yahoo.com>:

>
> What is the result of the post action?  A redirect?  JSP?
>
> Its probably best to post some of the relevant action code and struts.xml
> first, and then if we need to we can go into the Hibernate code.
>
> -D
>
> Márcio Gurgel wrote:
> >
> > Hi all!
> >
> > I'm using struts 2 + hibernate.
> > I've a strange problem, if someone could give me a hand I'll be so
> > tankfull.
> >
> > If I persist a object in my app every things go well and all
> relationchips
> > are stored correctey correctly.
> > The problem occours when I update this object... After the update all
> data
> > are stored correctly too, but the problem is that my page shows the old
> > object (different from database).
> >
> > This could be some kind of cash from struts 2? Or my problem is just
> > hibernate?
> >
> > I tryed this methods to force a refresh after bring the object from
> > database
> > session.refresh(obj)
> > session.flush()
> >
> > Tank so much for attention!
> >
> > Márcio Gurgel
> >
> >
>
> --
> View this message in context:
> http://www.nabble.com/Struts-2-%2B-Hibernate-question-tp17527841p17550934.html
> Sent from the Struts - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

Re: Struts 2 + Hibernate question

Posted by dusty <du...@yahoo.com>.
What is the result of the post action?  A redirect?  JSP?  

Its probably best to post some of the relevant action code and struts.xml
first, and then if we need to we can go into the Hibernate code.

-D

Márcio Gurgel wrote:
> 
> Hi all!
> 
> I'm using struts 2 + hibernate.
> I've a strange problem, if someone could give me a hand I'll be so
> tankfull.
> 
> If I persist a object in my app every things go well and all relationchips
> are stored correctey correctly.
> The problem occours when I update this object... After the update all data
> are stored correctly too, but the problem is that my page shows the old
> object (different from database).
> 
> This could be some kind of cash from struts 2? Or my problem is just
> hibernate?
> 
> I tryed this methods to force a refresh after bring the object from
> database
> session.refresh(obj)
> session.flush()
> 
> Tank so much for attention!
> 
> Márcio Gurgel
> 
> 

-- 
View this message in context: http://www.nabble.com/Struts-2-%2B-Hibernate-question-tp17527841p17550934.html
Sent from the Struts - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


similar problem

Posted by kattenok <an...@yandex.ru>.
I have similar problem. On one page of my site I configurate some settings
(forexample  attribute "country" set true). That changes set to data base (I
cheked it). Then I go to other page , where (if attribute "country" is true)
textbox "country"  is visible, but it isn't. The problem that nhibernate 
returns old value ("country" is false). And  there is one more strange thing
- nhibernate  cat return right value for fist load of page and old value for
second (if i press F5 ), or old value for fist load and right value  for
second or for third.
In other words if i press F5 I can't be sure what value I get(right or old).
Please help me.
-- 
View this message in context: http://www.nabble.com/Struts-2-%2B-Hibernate-question-tp17527841p18647606.html
Sent from the Struts - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Struts 2 + Hibernate question

Posted by Laurie Harper <la...@holoweb.net>.
Márcio Gurgel wrote:
> Hi all!
> 
> I'm using struts 2 + hibernate.
> I've a strange problem, if someone could give me a hand I'll be so tankfull..
> 
> If I persist a object in my app every things go well and all relationchips
> are stored correctey correctly.
> The problem occours when I update this object... After the update all data
> are stored correctly too, but the problem is that my page shows the old
> object (different from database).
> 
> This could be some kind of cash from struts 2? Or my problem is just
> hibernate?
> 
> I tryed this methods to force a refresh after bring the object from database
> session.refresh(obj)
> session.flush()

I can tell you that Struts doesn't cache your data anywhere for you. You 
may be storing a reference in the session or some other web-tier scope, 
holding it in a static field or otherwise keeping a stale reference 
somewhere. Or you may be seeing client-side page caching or even 
mis-configured caching at the Hibernate or database level.

You'll need to trace through your data access paths to determine at what 
point you're picking up the stale reference, and then figure out where 
that's coming from.

L.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org