I need to use query that fetches objects from multiple entity groups (which means I can't use transactions). Here's the method: @Override public Collection<Item> findInactiveItems(Date endDate) { inactiveItems = em.createNamedQuery("findInactiveItems").setParameter("endDate", endDate).getResultList(); if(null == inactiveItems) inactiveItems = new ArrayList<Item>(); inactiveItems.size(); return inactiveItems; } However, calling getResultList() causes the following error: Caused by: org.datanucleus.exceptions.NucleusUserException: Object Manager has been closed at org.datanucleus.ObjectManagerImpl.assertIsOpen(ObjectManagerImpl.java: 3876) at org.datanucleus.ObjectManagerImpl.getTransaction(ObjectManagerImpl.java: 596) at org.datanucleus.jpa.EntityTransactionImpl.isActive(EntityTransactionImpl.java: 61) at org.datanucleus.jpa.JPAQuery.getResultList(JPAQuery.java:158)
I found here on groups the same error posted with suggestions that using OpenEntityManagerInViewFilter should keep entity manager throughout the request. Unforfunately, I can't get this filter working because it tries to create a new entity manager factory while gae allows to create only one of those. Here is part of my web.xml <servlet> <servlet-name>context</servlet-name> <servlet-class> org.springframework.web.context.ContextLoaderServlet </servlet-class> <load-on-startup>1</load-on-startup> </servlet> <filter> <filter-name>OpenEntityManagerInViewFilter</filter-name> <filter- class>org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter</ filter-class> <init-param> <param-name>entityManagerFactory</param-name> <param-value>entityManagerFactory</param-value> </init-param> </filter> <filter-mapping> <filter-name>OpenEntityManagerInViewFilter</filter-name> <url-pattern>*.html</url-pattern> </filter-mapping> And part of applicationContext.xml: <bean id="entityManagerFactory" name="entityManagerFactory" class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean" scope="singleton"> <property name="persistenceUnitName" value="transactions-optional" / > </bean> <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager" scope="singleton"> <property name="entityManagerFactory" ref="entityManagerFactory" /> </bean> And here is the error caused by filter: org.springframework.web.servlet.FrameworkServlet initServletBean: Context initialization failed org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in ServletContext resource [/WEB-INF/allewidok-servlet.xml]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: Provider error. Provider: org.datanucleus.store.appengine.jpa.DatastorePersistenceProvider (...) Caused by: java.lang.IllegalStateException: Application code attempted to create a EntityManagerFactory named transactions-optional, but one with this name already exists! Instances of EntityManagerFactory are extremely slow to create and it is usually not necessary to create one with a given name more than once. Instead, create a singleton and share it throughout your code. If you really do need to create a duplicate EntityManagerFactory (such as for a unittest suite), set the appengine.orm.disable.duplicate.emf.exception system property to avoid this error. at org.datanucleus.store.appengine.jpa.DatastoreEntityManagerFactory.checkForRepeatedAllocation(DatastoreEntityManagerFactory.java: 136) at org.datanucleus.store.appengine.jpa.DatastoreEntityManagerFactory.<init>(DatastoreEntityManagerFactory.java: 64) at org.datanucleus.store.appengine.jpa.DatastorePersistenceProvider.createEntityManagerFactory(DatastorePersistenceProvider.java: 35) at javax.persistence.Persistence.createFactory(Persistence.java:172) So, has anybody actually used OpenEntityManagerInViewFilter on GAE? -- You received this message because you are subscribed to the Google Groups "Google App Engine for Java" group. To post to this group, send email to google-appengine-j...@googlegroups.com. To unsubscribe from this group, send email to google-appengine-java+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/google-appengine-java?hl=en.