openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Richard Luong <rlu...@gmail.com>
Subject Slice closing EntityManager on named queries
Date Wed, 20 Apr 2011 20:23:52 GMT
I'm using OpenJPA 2.1.0.  When executing a named query the first time 
(which goes to all slices), everything works fine.  However, on the 
second call to the named query, it appears that openjpa creates and 
closes the EntityManager instantly.  This then causes and 
IllegalStateException.  The code works fine when running on a non-sliced 
environment.  I'm able to call entityManager.find() multiple times 
without issue.

I'm pasting the log and my persistence unit below.  Any help would be 
appreciated.

Thanks,
Richard.

Code Snippet:
     public List<Permissions> findPermissionsByUserResource(Long userID, 
String resource) {
         log.info("about to use entityMgr");
         Query query = entityManager.createNamedQuery("permsByUser");
         query.setParameter("userIDParam", userID);
         query.setParameter("resourceParam", resource);
         Set<Permissions> results = new LinkedHashSet<Permissions>();
         results.addAll(query.getResultList());
         log.info("finished first query.  about to execute second");
         query = entityManager.createNamedQuery("permsByUserRoles");
         query.setParameter("userIDParam", userID);
         query.setParameter("resourceParam", resource);
         results.addAll(query.getResultList());
         log.info("finished second query. about to return.");
         return new ArrayList<Permissions>(results);
     }


Error Log:

... (1st time query is run)...

77779  platform_slice  TRACE  [http-8080-1] openjpa.Runtime - Found 
datasource1: datasource 1730863804 from configuration. StoreContext: 
org.apache.openjpa.kernel.BrokerImpl@308bd98e
77770  platform_slice.platform  TRACE  [http-8080-1] openjpa.Runtime - 
Found datasource1: datasource 1730863804 from configuration. 
StoreContext: org.apache.openjpa.kernel.BrokerImpl@308bd98e
77698  platform_slice.platform1  TRACE  [http-8080-1] openjpa.Runtime - 
Found datasource1: datasource 762843784 from configuration. 
StoreContext: org.apache.openjpa.kernel.BrokerImpl@308bd98e
77696  platform_slice.platform2  TRACE  [http-8080-1] openjpa.Runtime - 
Found datasource1: datasource 638105098 from configuration. 
StoreContext: org.apache.openjpa.kernel.BrokerImpl@308bd98e
77826  platform_slice  TRACE  [http-8080-1] openjpa.Runtime - 
org.apache.openjpa.persistence.EntityManagerFactoryImpl@2b8ca663 created 
EntityManager org.apache.openjpa.persistence.EntityManagerImpl@308bd98e.
2011-04-20 12:57:35,393 INFO [xxx.PermissionsDAOImpl] - about to use 
entityMgr
78122  platform_slice  TRACE  [http-8080-1] openjpa.Runtime - Query 
"SELECT perms FROM Permissions perms JOIN perms.users usrs JOIN 
perms.resource res WHERE usrs.uid = :userIDParam AND res.nameField = 
:resourceParam " is cached."
78308  platform_slice  WARN   [http-8080-1] openjpa.Runtime - Query 
"SELECT perms FROM Permissions perms JOIN perms.users usrs JOIN 
perms.resource res WHERE usrs.uid = :userIDParam AND res.nameField = 
:resourceParam " is removed from cache  excluded permanently. Query 
"SELECT perms FROM Permissions perms JOIN perms.users usrs JOIN 
perms.resource res WHERE usrs.uid = :userIDParam AND res.nameField = 
:resourceParam " is not cached because its result is not obtained by 
executing a select statement. This can happen if the query was evaluated 
in-memory. The result was provided by 
org.apache.openjpa.lib.rop.MergedResultObjectProvider.  .
2011-04-20 12:57:35,874 INFO 
[com.edelements.platform.dao.impl.PermissionsDAOImpl] - finished first 
query.  about to execute second
78320  platform_slice  TRACE  [http-8080-1] openjpa.Runtime - Query 
"SELECT perms FROM Permissions perms JOIN perms.resource res JOIN 
perms.roles rols JOIN rols.users usrs WHERE usrs.uid = :userIDParam AND 
res.nameField = :resourceParam " is cached."
78363  platform_slice  WARN   [http-8080-1] openjpa.Runtime - Query 
"SELECT perms FROM Permissions perms JOIN perms.resource res JOIN 
perms.roles rols JOIN rols.users usrs WHERE usrs.uid = :userIDParam AND 
res.nameField = :resourceParam " is removed from cache  excluded 
permanently. Query "SELECT perms FROM Permissions perms JOIN 
perms.resource res JOIN perms.roles rols JOIN rols.users usrs WHERE 
usrs.uid = :userIDParam AND res.nameField = :resourceParam " is not 
cached because its result is not obtained by executing a select 
statement. This can happen if the query was evaluated in-memory. The 
result was provided by 
org.apache.openjpa.lib.rop.MergedResultObjectProvider.  .
2011-04-20 12:57:35,926 INFO 
[com.edelements.platform.dao.impl.PermissionsDAOImpl] - finished second 
query. about to return.
78366  platform_slice  TRACE  [http-8080-1] openjpa.Runtime - 
org.apache.openjpa.persistence.EntityManagerImpl@308bd98e.close() invoked.

... (2nd time query is run)...

78630  platform_slice  TRACE  [http-8080-1] openjpa.Runtime - Found 
datasource1: datasource 1730863804 from configuration. StoreContext: 
org.apache.openjpa.kernel.BrokerImpl@37efd36
78622  platform_slice.platform  TRACE  [http-8080-1] openjpa.Runtime - 
Found datasource1: datasource 1730863804 from configuration. 
StoreContext: org.apache.openjpa.kernel.BrokerImpl@37efd36
78550  platform_slice.platform1  TRACE  [http-8080-1] openjpa.Runtime - 
Found datasource1: datasource 762843784 from configuration. 
StoreContext: org.apache.openjpa.kernel.BrokerImpl@37efd36
78547  platform_slice.platform2  TRACE  [http-8080-1] openjpa.Runtime - 
Found datasource1: datasource 638105098 from configuration. 
StoreContext: org.apache.openjpa.kernel.BrokerImpl@37efd36
78631  platform_slice  TRACE  [http-8080-1] openjpa.Runtime - 
org.apache.openjpa.persistence.EntityManagerFactoryImpl@2b8ca663 created 
EntityManager org.apache.openjpa.persistence.EntityManagerImpl@37efd36.
2011-04-20 12:57:36,194 INFO 
[com.edelements.platform.dao.impl.PermissionsDAOImpl] - about to use 
entityMgr
78633  platform_slice  TRACE  [http-8080-1] openjpa.Runtime - 
org.apache.openjpa.persistence.EntityManagerImpl@37efd36.close() invoked.
Apr 20, 2011 12:57:36 PM org.apache.catalina.core.ApplicationDispatcher 
invoke
SEVERE: Servlet.service() for servlet jsp threw exception
java.lang.IllegalStateException
     at org.apache.openjpa.kernel.BrokerImpl.free(BrokerImpl.java:4384)
     at org.apache.openjpa.kernel.BrokerImpl.close(BrokerImpl.java:4311)
     at 
org.apache.openjpa.kernel.DelegatingBroker.close(DelegatingBroker.java:1346)
     at 
org.apache.openjpa.persistence.EntityManagerImpl.close(EntityManagerImpl.java:1284)
     at 
org.springframework.orm.jpa.EntityManagerFactoryUtils.closeEntityManager(EntityManagerFactoryUtils.java:331)
     at 
org.springframework.orm.jpa.JpaTransactionManager.doCleanupAfterCompletion(JpaTransactionManager.java:550)
     at 
org.springframework.transaction.support.AbstractPlatformTransactionManager.cleanupAfterCompletion(AbstractPlatformTransactionManager.java:1011)
     at 
org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:804)
     at 
org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:723)
     at 
org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:393)
     at 
org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:120)
     at 
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
     at 
org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
     at $Proxy15.findPermissionsByUserResource(Unknown Source)
     at xxx.LoginController.loginSimple(LoginController.java:50)
     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
     at 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
     at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
     at java.lang.reflect.Method.invoke(Method.java:597)
     at 
org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:176)
     at 
org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:426)
     at 
org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:414)
     at 
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:790)
     at 
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:719)
     at 
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:644)
     at 
org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:560)
     at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
     at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
     at 
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
     at 
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
     at 
org.apache.shiro.web.servlet.AbstractShiroFilter.executeChain(AbstractShiroFilter.java:359)
     at 
org.apache.shiro.web.servlet.AbstractShiroFilter$1.call(AbstractShiroFilter.java:275)
     at 
org.apache.shiro.subject.support.SubjectCallable.doCall(SubjectCallable.java:90)
     at 
org.apache.shiro.subject.support.SubjectCallable.call(SubjectCallable.java:83)
     at 
org.apache.shiro.subject.support.DelegatingSubject.execute(DelegatingSubject.java:344)
     at 
org.apache.shiro.web.servlet.AbstractShiroFilter.doFilterInternal(AbstractShiroFilter.java:272)
     at 
org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:81)
     at 
org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:237)
     at 
org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:167)
     at 
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
     at 
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
     at 
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
     at 
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
     at 
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
     at 
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
     at 
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
     at 
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
     at 
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:857)
     at 
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
     at 
org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
     at java.lang.Thread.run(Thread.java:662)
Apr 20, 2011 12:57:36 PM org.apache.catalina.core.StandardWrapperValve 
invoke
SEVERE: Servlet.service() for servlet spring threw exception
java.lang.IllegalStateException
     at org.apache.openjpa.kernel.BrokerImpl.free(BrokerImpl.java:4384)
     at org.apache.openjpa.kernel.BrokerImpl.close(BrokerImpl.java:4311)
     at 
org.apache.openjpa.kernel.DelegatingBroker.close(DelegatingBroker.java:1346)
     at 
org.apache.openjpa.persistence.EntityManagerImpl.close(EntityManagerImpl.java:1284)
     at 
org.springframework.orm.jpa.EntityManagerFactoryUtils.closeEntityManager(EntityManagerFactoryUtils.java:331)
     at 
org.springframework.orm.jpa.JpaTransactionManager.doCleanupAfterCompletion(JpaTransactionManager.java:550)
     at 
org.springframework.transaction.support.AbstractPlatformTransactionManager.cleanupAfterCompletion(AbstractPlatformTransactionManager.java:1011)
     at 
org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:804)
     at 
org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:723)
     at 
org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:393)
     at 
org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:120)
     at 
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
     at 
org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
     at $Proxy15.findPermissionsByUserResource(Unknown Source)
     at xxx.LoginController.loginSimple(LoginController.java:50)
     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
     at 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
     at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
     at java.lang.reflect.Method.invoke(Method.java:597)
     at 
org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:176)
     at 
org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:426)
     at 
org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:414)
     at 
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:790)
     at 
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:719)
     at 
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:644)
     at 
org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:560)
     at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
     at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
     at 
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
     at 
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
     at 
org.apache.shiro.web.servlet.AbstractShiroFilter.executeChain(AbstractShiroFilter.java:359)
     at 
org.apache.shiro.web.servlet.AbstractShiroFilter$1.call(AbstractShiroFilter.java:275)
     at 
org.apache.shiro.subject.support.SubjectCallable.doCall(SubjectCallable.java:90)
     at 
org.apache.shiro.subject.support.SubjectCallable.call(SubjectCallable.java:83)
     at 
org.apache.shiro.subject.support.DelegatingSubject.execute(DelegatingSubject.java:344)
     at 
org.apache.shiro.web.servlet.AbstractShiroFilter.doFilterInternal(AbstractShiroFilter.java:272)
     at 
org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:81)
     at 
org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:237)
     at 
org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:167)
     at 
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
     at 
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
     at 
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
     at 
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
     at 
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
     at 
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
     at 
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
     at 
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
     at 
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:857)
     at 
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
     at 
org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
     at java.lang.Thread.run(Thread.java:662)


Persistence Unit:
<persistence-unit name="platform_slice">
<provider>
             org.apache.openjpa.persistence.PersistenceProviderImpl
</provider>

<properties>
<property name="openjpa.Log" value="Runtime=TRACE, DefaultLevel=WARN, 
Tool=INFO"/>
<property name="openjpa.BrokerFactory" value="slice"/>
<property name="openjpa.slice.Names"   
value="platform,platform1,platform2"/>
<property name="openjpa.slice.Master"  value="platform"/>
<!-- Lenient: Allows DB to continue, even when one slice is unavailable. -->
<property name="openjpa.slice.Lenient" value="true"/>

<property name="openjpa.ConnectionDriverName"
                       value="com.mysql.jdbc.Driver"/>
<property name="openjpa.ConnectionUserName" value="root"/>
<property name="openjpa.ConnectionPassword" value="password"/>
<property name="openjpa.slice.platform.ConnectionURL"
                       value="jdbc:mysql://127.0.0.1:3306/platform"/>
<property name="openjpa.slice.platform1.ConnectionURL"
                       value="jdbc:mysql://127.0.0.1:3306/platform1"/>
<property name="openjpa.slice.platform2.ConnectionURL"
                       value="jdbc:mysql://127.0.0.1:3306/platform2"/>

<property name="openjpa.slice.DistributionPolicy"
                            value="xxx.ShardDistributionPolicy"/>
<property name="openjpa.slice.ReplicatedTypes"
                                value="xxx.Institutions,xxx.Users"/>

</properties>
</persistence-unit>


Mime
View raw message