You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Al Sutton <al...@alsutton.com> on 2008/06/13 19:12:48 UTC

[OT] Re: [JPA more than Struts 2] Two action classes ?

Milan,

Please read the EntityManager JavaDoc at 
http://java.sun.com/javaee/5/docs/api/javax/persistence/EntityManager.html 
and http://www.oracle.com/technology/pub/articles/gupta-jpa.html You'll 
see these explain why you can't simply put the object into a session and 
keep using it.

You need to store the ID in the web page, refetch the object, then 
update with the data posted from the form whilst ensuring your security 
constraints are not violated.

Al.


Milan Milanovic wrote:
> Yes, EntityManager will be closed, but it always closes whenevery you do
> something (read/write) your object from database, isn't it ? When I read for
> example Fruit (id=1) from database, change it and try to save it will know
> with new EntityManager instance to save it because of id number ?
>
> --
> Thx, Milan
>
>
> Al Sutton wrote:
>   
>> If you're using a persistence framework (Hibernate, JPA, etc.) then No.
>>
>> During after the first request the EntityManager will be closed, so when 
>> you access it during the second request updates will not be propagated 
>> to the database.
>>
>> Al.
>>
>> Milan Milanovic wrote:
>>     
>>> But could I pass object through session object ?
>>>
>>>
>>> newton.dave wrote:
>>>   
>>>       
>>>> --- On Fri, 6/13/08, Milan Milanovic <mi...@yahoo.com> wrote:
>>>>     
>>>>         
>>>>> Yes that's what I want. The first action search in database and show
>>>>> the 
>>>>> list of Fruits. Then user click on one and that concrete Fruit object
>>>>> is
>>>>> passed to other action for editing.
>>>>>       
>>>>>           
>>>> All you can pass in an HTTP request is a string.
>>>>
>>>> You can *use* that string to create or retrieve an object.
>>>>
>>>> Dave
>>>>
>>>>
>>>> ---------------------------------------------------------------------
>>>> 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
>>
>>
>>
>>     
>
>   


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