Hi Mike,
Thank you for your professional explanation.
I found this issue was nothing to do with Spring. The root cause is I
cache the EntityManager in some complicated scenarios.
And I also found some configuration items related with cache will
affect this case also.
Thank you again.

Cheers,
Yu Wang

On Mon, Jun 8, 2009 at 10:26 PM, Michael Dick<michael.d.d...@gmail.com> wrote:
> Hi Yu Wang,
>
> I'm not sure how to configure Spring to not cache the EntityManager. My
> guess is that Spring would cache an EntityManager for the lifetime of a
> transaction and then close it at the end of the tran. The best reference I
> could find is here [1].
>
> Using an entirely new EntityManagerFactory should also resolve the problem
> (that will result in a new EntityManager and a new connection to the
> database).
>
> Another thing to look into is the openjpa.ConnectionRetainMode property [2].
> You should have this set to "transaction" or "on-demand" to make sure the
> EntityManager isn't caching a connection to Derby.
>
> [1] http://static.springframework.org/spring/docs/2.5.x/reference/orm.html
> [2]
> http://openjpa.apache.org/builds/latest/docs/manual/manual.html#ref_guide_dbsetup_retain
>
> Hope this helps,
> -mike
>
>
>
> On Mon, Jun 8, 2009 at 12:22 AM, wang yu <wangy...@gmail.com> wrote:
>
>> Hi Mike,
>> Following is how I close cache:
>>
>>                        <property name="openjpa.DataCache" value="false" />
>>                        <property name="openjpa.QueryCache" value="false" />
>>                        <property name="openjpa.jdbc.QuerySQLCache"
>> value="false" />
>>                        <property name="openjpa.QueryCompilationCache"
>> value="false" />
>>
>> Your concern is spring cache the EntityManager, right? How can I avoid
>> this? Should I use a brand new entityManagerFactory?
>>
>> Regards,
>> Yu Wang
>>
>>
>> On Fri, Jun 5, 2009 at 9:56 PM, Michael Dick<michael.d.d...@gmail.com>
>> wrote:
>> > Hi Yu Wang,
>> >
>> > It sounds like someone is maintaining a pool of EntityManagers. The
>> > assertOpen method isn't checking Derby, it's concerned with the state of
>> the
>> > EntityManager itself.
>> >
>> > How did you close the cache of OpenJPA EntityManagers? I have very little
>> > experience with Spring, but the stack makes it look like it's handing out
>> > the EntityManager that is being used.
>> >
>> > -mike
>> >
>> > On Fri, Jun 5, 2009 at 2:44 AM, wang yu <wangy...@gmail.com> wrote:
>> >
>> >> Hello,
>> >> My application uses Tomcat6,derby,spring and OpenJPA 1.20.
>> >> My case is stopping derby database and restarting it. And I found even
>> >> if I catch the database connection broken exception and create an new
>> >> EntityManager successfully after derby restarts, the following
>> >> exception stack will be printed :
>> >>
>> >> <2009-06-05 15:22:21,140> <ERROR> <com.***.ds.Persister.persist:203>
>> >> <Persistence-thread-1> <The context has been closed.  The stack trace
>> >> at which the context was closed is available if Runtime=TRACE logging
>> >> is enabl...@agent
>> >>
>> (key=Domain7:machine0:0,machine0;jsessionid=0F915CC5A079F150E6C1E34661661831)>
>> >> <openjpa-1.2.1-r752877:753278 fatal user error>
>> >> org.apache.openjpa.persistence.InvalidStateException: The context has
>> >> been closed.  The stack trace at which the context was closed is
>> >> available if Runtime=TRACE logging is enabled.
>> >>        at
>> >> org.apache.openjpa.kernel.BrokerImpl.assertOpen(BrokerImpl.java:4367)
>> >>        at
>> >>
>> org.apache.openjpa.kernel.BrokerImpl.beginOperation(BrokerImpl.java:1766)
>> >>        at
>> >> org.apache.openjpa.kernel.BrokerImpl.newQuery(BrokerImpl.java:3483)
>> >>        at
>> >>
>> org.apache.openjpa.kernel.DelegatingBroker.newQuery(DelegatingBroker.java:1225)
>> >>        at
>> >>
>> org.apache.openjpa.persistence.EntityManagerImpl.createQuery(EntityManagerImpl.java:870)
>> >>        at
>> >>
>> org.apache.openjpa.persistence.EntityManagerImpl.createQuery(EntityManagerImpl.java:865)
>> >>        at
>> >>
>> org.apache.openjpa.persistence.EntityManagerImpl.createQuery(EntityManagerImpl.java:77)
>> >>        at sun.reflect.GeneratedMethodAccessor32.invoke(Unknown Source)
>> >>        at
>> >>
>> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>> >>        at java.lang.reflect.Method.invoke(Method.java:585)
>> >>        at
>> >>
>> org.springframework.orm.jpa.ExtendedEntityManagerCreator$ExtendedEntityManagerInvocationHandler.invoke(ExtendedEntityManagerCreator.java:357)
>> >>        at $Proxy15.createQuery(Unknown Source)
>> >>        at
>> >> com.***.dao.JPAImpl.CallpathDaoImpl.findByName(CallpathDaoImpl.java:31)
>> >>        at
>> >> com.***.dao.JPAImpl.CallpathDaoImpl.findByName(CallpathDaoImpl.java:18)
>> >>        at com.***.ds.Persister.persist(Persister.java:139)
>> >>        at com.***.ds.PersistRunner.run(PersistRunner.java:44)
>> >>        at
>> >> java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:417)
>> >>        at
>> >> java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:269)
>> >>        at java.util.concurrent.FutureTask.run(FutureTask.java:123)
>> >>        at
>> >>
>> java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:65)
>> >>        at
>> >>
>> java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:168)
>> >>        at
>> >>
>> java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:650)
>> >>        at
>> >>
>> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:675)
>> >>        at java.lang.Thread.run(Thread.java:595)
>> >>
>> >> And I ensure the new EntityManager connect derby successfully by
>> >> netstat -an|grep 1527.
>> >> I closed all cache of OpenJPA but same error still happen.
>> >>
>> >>
>> >> Regards,
>> >> Yu Wang
>> >>
>> >
>>
>

Reply via email to