Dru Devore wrote:
>> -------- Original Message --------
>> Subject: Re: Glassfish Shutdown with JPA
>> From: Mitesh Meswani <Mitesh.Meswani_at_Sun.COM>
>> Date: Wed, October 15, 2008 2:49 pm
>> To: persistence_at_glassfish.dev.java.net
>>
>>
>> Dru Devore wrote:
>>
>>> I have a timer that goes through a list of objects, performs an action
>>> on it, logs the object, sets a boolean, and persists it back to the
>>> database. The boolean indicates that the object is finished and should
>>> not be acted on again. So I have the following sudo loop:
>>>
>>>
>
> New Transaction --- (This is all contained in a single EJB method that
> requires a new transaction)
>
>>> list objects = get object from the database
>>> while (more objects) {
>>> act on object
>>> log the object
>>> set boolean
>>> persist object
>>> }
>>>
> End Transation ---
>
>
>> At what point does the transaction commit happen?
>>
>>> I had a list size of 1152 the other day and during the loop I shut
>>> down the server. After I started the server back up I noticed that it
>>> was logging the same objects again. I checked the logs and saw that
>>> all the actions and persistence happened
>>>
>> Did you actually see update statements going to database in the log?
>>
>
> I have not seen any update statements from the the JPA classes. I know
> the update works though because the only time I dont get the boolean
> updated is when I shut down the server in the middle of the processing.
>
> I am guessing that I am going to have to implement a finer grained
> transaction to get the action I want.
>
It seems the method might be long running and you are in middle of the
method when the appserver shuts down. Which explains the behavior. This
should not lead to any inconsistencies as either all or none of the rows
would be updated to database.
> Let me ask another question while I have your attention.
>
> Another situation:
> I perform a query and get a list of objects. I then change the data
> directly in the database but when the same object is queried again the
> changes made directly through sql are not reflected in the object. I
> tried to flush the object but I have not seen it work solve the problem.
>
Toplink relies on second level cache (see
http://weblogs.java.net/blog/guruwons/archive/2006/09/understanding_t_1.html
for more details). If you are expecting parallel updates to the
underlying data, you need to query using hint "toplink.refresh" set to
"true" to refresh the second level cache
-Mitesh
>
>> Thanks,
>> Mitesh
>>
>>> as it should have but the DB simply was not reflecting the boolean
>>> indicator properly though I know it was set and persisted.
>>>
>>> So it appears that the objects were simply not transfered from the
>>> cache to the DB. I am using EJB 3 with toplink.
>>>
>>>
>>> -------- Original Message --------
>>> Subject: Re: Glassfish Shutdown with JPA
>>> From: Mitesh Meswani <Mitesh.Meswani_at_Sun.COM>
>>> Date: Wed, October 15, 2008 2:19 pm
>>> To: persistence_at_glassfish.dev.java.net
>>>
>>> Can you please give some more details on what do you mean by "does
>>> not
>>> appear to be saving the JPA persisted objects before shutdown.".
>>> Objects
>>> saved using em.persist() will be saved to database at each
>>> transaction
>>> completion. There is nothing special you will need to do.
>>>
>>> -Mitesh
>>>
>>> Dru Devore wrote:
>>> > I have an application which does not appear to be saving the JPA
>>> > persisted objects before shutdown.
>>> >
>>> > Yes, the objects are being persisted before the shutdown but it
>>> > appears that they are not making it out of the cache. Is there
>>> > something I have to do during shutdown of the application server to
>>> > ensure the objects are actually stored.
>>> >
>>> >
>>>
>>>
>
>