struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Márcio Gurgel" <marcio....@gmail.com>
Subject Re: Struts 2 + Hibernate question [RESOLVED]
Date Sat, 31 May 2008 20:23:28 GMT
Uh Oh...
It's not really ok...
After I update a object from a jsp all field are shown in the current jsp
ok, but when I'm comming from a link (searh a object) are displayed the old
state (before update). /:
Now I just dont know what to do. Seems that struts still caching my object.
I have to run against the time, I have to present my final academic project
next month.

Any ideias? I'm really needing a hand.

Márcio Gurgel


2008/5/30 Márcio Gurgel <marcio.rga@gmail.com>:

> I guess that this is the end of my saga.
>
> Stewart showed me the way and I resolve this by calling the method to open
> data.
> Before I was calling this method via redirectAtion, now I just call by my
> action class and just like magic everything went well.
> * I changed my result to return a jsp not a action.
>
> Thanks so much to: Sutton, Dusty, Stewart, Owen and Martin. I hope help you
> also in another opportunity!
>
> Here's the code:
>
> ---- ACTION TO UPDATE ----
> * After update I called setValuesAbrirPageFsc to populate my view (mainly
> autocomplers and s:selects)
>
> 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);
>
>
>             setClienteFsc(clienteFsc);
>
>             //HERE I CALL THE MENTIONED METHOD
>             setValuesAbrirPageFsc();
>
>         } catch (Exception e) {
>             addActionError(SgvdbaConstants.ERRO_DEFAULT + e.getMessage());
>             return Action.INPUT;
>         }
>         return Action.SUCCESS;
>     }
>
>
> ---- POPULATES A JSP ----
> private void setValuesAbrirPageFsc(){
>         if (clienteFsc != null){
>             if (clienteFsc.getCd() != null){
>                 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++;
>                 }
>             }
>
>         }
>     }
>
>
> 2008/5/30 Márcio Gurgel <marcio.rga@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 <owen.berry@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 <marcio.rga@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
>>> >
>>>
>>
>>
>

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