Re: Slice and connection pools
That's correct Mike. Also, thus far, I could only get OpenJPA slice working with DBCP. There seems to be an issue with using Tomcat Connection Pool. Once I have more time to trace/debug what's going on, I'll post it on a new thread. Richard. On Wed, Aug 3, 2011 at 11:01 AM, Michael Dick wrote: > I think Richard's configuration is correct. The only catch, which he > pointed > out, is that you do have to specify the DBDictionary to use. Maybe I > missed > something though? > > I'm not sure whether having to specify the DBDictionary is the result of > the > automagic connection pool support, but for the time being we should update > the documentation to reflect this requirement. > > In case I missed something, here's the persistence unit from the > openjpa-slice module that I used to reproduce the problem : > http://pastebin.com/W47zy9ms > > -mike > > On Wed, Aug 3, 2011 at 10:05 AM, Pinaki Poddar wrote: > > > The connection pooling can be configured for each slice as you would do > > normally [1] for a single database. The property names however will > change. > > > > > > > > However, we have introduced some new mechanics that can configure a > > connection pool automagically when commons dbcp in classpath. I do not > > think > > that this new mechanics have taken Slice connection establishment into > > account. > > > > > > [1] > > > > > http://openjpa.apache.org/faq.html#FAQ-HowdoIenableconnectionpoolinginOpenJPA%253F > > > > - > > Pinaki Poddar > > Chair, Apache OpenJPA Project > > -- > > View this message in context: > > > http://openjpa.208410.n2.nabble.com/Slice-and-connection-pools-tp6643295p6649074.html > > Sent from the OpenJPA Users mailing list archive at Nabble.com. > > >
Re: Slice and connection pools
Ok, I've found a workaround. The code seems to be failing because it cannot determine the DBDictionary to use. It uses the ConnectionURL (null) and the ConnectionDriverName (which points to the pool) to determine the DBDictionary. Once that fails, it attempts to connect to the database to try and determine the dictionary. It tries to grab a slice, but the collection of slices is empty, since this is all happening during the process of adding the first slice. With no slice, it cannot connect and throws no slices configured exception. The workaround that I'm doing is explicitly setting the DBDictionary with the following in my persistence-unit properties: Hope that helps anyone else that runs into the same issue. Richard. On Tue, Aug 2, 2011 at 8:51 AM, RICHARD LUONG wrote: > I'm getting the following error: > > Caused by: > org.apache.openjpa.persistence.ArgumentException: No slices are configured > or available > at > org.apache.openjpa.slice.jdbc.DistributedJDBCConfigurationImpl.createDistributedDataStore(DistributedJDBCConfigurationImpl.java:363) > at > org.apache.openjpa.slice.jdbc.DistributedJDBCConfigurationImpl.createConnectionFactory(DistributedJDBCConfigurationImpl.java:626) > at > org.apache.openjpa.jdbc.conf.JDBCConfigurationImpl.getDBDictionaryInstance(JDBCConfigurationImpl.java:602) > at > org.apache.openjpa.jdbc.meta.MappingDefaultsImpl.setConfiguration(MappingDefaultsImpl.java:878) > at > org.apache.openjpa.lib.conf.Configurations.configureInstance(Configurations.java:486) > at > org.apache.openjpa.lib.conf.Configurations.configureInstance(Configurations.java:443) > at > org.apache.openjpa.lib.conf.PluginValue.instantiate(PluginValue.java:104) > at org.apache.openjpa.lib.conf.ObjectValue.instantiate(ObjectValue.java:83) > at > org.apache.openjpa.jdbc.conf.JDBCConfigurationImpl.getMappingDefaultsInstance(JDBCConfigurationImpl.java:706) > at > org.apache.openjpa.slice.jdbc.DistributedJDBCConfigurationImpl.newSlice(DistributedJDBCConfigurationImpl.java:467) > at > org.apache.openjpa.slice.jdbc.DistributedJDBCConfigurationImpl.fromProperties(DistributedJDBCConfigurationImpl.java:618) > at > org.apache.openjpa.lib.conf.MapConfigurationProvider.setInto(MapConfigurationProvider.java:85) > at > org.apache.openjpa.persistence.PersistenceProductDerivation$ConfigurationProviderImpl.setInto(PersistenceProductDerivation.java:698) > at > org.apache.openjpa.slice.jdbc.DistributedJDBCBrokerFactory.newInstance(DistributedJDBCBrokerFactory.java:56) > 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.apache.openjpa.kernel.Bootstrap.invokeFactory(Bootstrap.java:131) > at org.apache.openjpa.kernel.Bootstrap.newBrokerFactory(Bootstrap.java:65) > at > org.apache.openjpa.persistence.PersistenceProviderImpl.getBrokerFactory(PersistenceProviderImpl.java:151) > at > org.apache.openjpa.persistence.PersistenceProviderImpl.createContainerEntityManagerFactory(PersistenceProviderImpl.java:191) > at > org.apache.openjpa.persistence.PersistenceProviderImpl.createContainerEntityManagerFactory(PersistenceProviderImpl.java:66) > at > org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:225) > at > org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:308) > at > org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1477) > at > org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1417) > ... 130 more > > On Tue, Aug 2, 2011 at 6:29 AM, Rick Curtis wrote: > >> What is the error that you are seeing? >> >> On Mon, Aug 1, 2011 at 8:03 PM, RICHARD LUONG wrote: >> >> > Hi, >> > >> > Does Slice support using a connection pool? I was able to get the >> > connection pool working when not using Slice with the following >> > persistence-unit: >> > >> > >> > >> >org.apache.openjpa.persistence.PersistenceProviderImpl >> > >> > >> > >> > > >value="DriverClassName=com.mysql.jdbc.Driver, >> > Url=jdbc:mysql://url:3306/test, >> > MaxActive=300, >> > TestOnBorrow=true, >> >
Re: Slice and connection pools
I'm getting the following error: Caused by: org.apache.openjpa.persistence.ArgumentException: No slices are configured or available at org.apache.openjpa.slice.jdbc.DistributedJDBCConfigurationImpl.createDistributedDataStore(DistributedJDBCConfigurationImpl.java:363) at org.apache.openjpa.slice.jdbc.DistributedJDBCConfigurationImpl.createConnectionFactory(DistributedJDBCConfigurationImpl.java:626) at org.apache.openjpa.jdbc.conf.JDBCConfigurationImpl.getDBDictionaryInstance(JDBCConfigurationImpl.java:602) at org.apache.openjpa.jdbc.meta.MappingDefaultsImpl.setConfiguration(MappingDefaultsImpl.java:878) at org.apache.openjpa.lib.conf.Configurations.configureInstance(Configurations.java:486) at org.apache.openjpa.lib.conf.Configurations.configureInstance(Configurations.java:443) at org.apache.openjpa.lib.conf.PluginValue.instantiate(PluginValue.java:104) at org.apache.openjpa.lib.conf.ObjectValue.instantiate(ObjectValue.java:83) at org.apache.openjpa.jdbc.conf.JDBCConfigurationImpl.getMappingDefaultsInstance(JDBCConfigurationImpl.java:706) at org.apache.openjpa.slice.jdbc.DistributedJDBCConfigurationImpl.newSlice(DistributedJDBCConfigurationImpl.java:467) at org.apache.openjpa.slice.jdbc.DistributedJDBCConfigurationImpl.fromProperties(DistributedJDBCConfigurationImpl.java:618) at org.apache.openjpa.lib.conf.MapConfigurationProvider.setInto(MapConfigurationProvider.java:85) at org.apache.openjpa.persistence.PersistenceProductDerivation$ConfigurationProviderImpl.setInto(PersistenceProductDerivation.java:698) at org.apache.openjpa.slice.jdbc.DistributedJDBCBrokerFactory.newInstance(DistributedJDBCBrokerFactory.java:56) 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.apache.openjpa.kernel.Bootstrap.invokeFactory(Bootstrap.java:131) at org.apache.openjpa.kernel.Bootstrap.newBrokerFactory(Bootstrap.java:65) at org.apache.openjpa.persistence.PersistenceProviderImpl.getBrokerFactory(PersistenceProviderImpl.java:151) at org.apache.openjpa.persistence.PersistenceProviderImpl.createContainerEntityManagerFactory(PersistenceProviderImpl.java:191) at org.apache.openjpa.persistence.PersistenceProviderImpl.createContainerEntityManagerFactory(PersistenceProviderImpl.java:66) at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:225) at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:308) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1477) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1417) ... 130 more On Tue, Aug 2, 2011 at 6:29 AM, Rick Curtis wrote: > What is the error that you are seeing? > > On Mon, Aug 1, 2011 at 8:03 PM, RICHARD LUONG wrote: > > > Hi, > > > > Does Slice support using a connection pool? I was able to get the > > connection pool working when not using Slice with the following > > persistence-unit: > > > > > > > >org.apache.openjpa.persistence.PersistenceProviderImpl > > > > > > > > >value="DriverClassName=com.mysql.jdbc.Driver, > > Url=jdbc:mysql://url:3306/test, > > MaxActive=300, > > TestOnBorrow=true, > > Username=user, > > Password=password"/> > > >value="org.apache.commons.dbcp.BasicDataSource"/> > > > > > > > > However, I got an error when attempting to use it in Slice, with the > > following: > > > > > > > >org.apache.openjpa.persistence.PersistenceProviderImpl > > > > > > > > > > > > > > > > > > > > > > > value="org.apache.commons.dbcp.BasicDataSource"/> > > > > >value="DriverClassName=com.mysql.jdbc.Driver, > > Url=jdbc:mysql://url:3306/test, > > MaxActive=300, > > TestOnBorrow=true, > > Username=user, > > Password=password"/> > > > > > value="com.service.openjpa.DistributeByInstitutionPolicy"/> > > > > value="com.service.openjpa.ShardFinderTargetPolicy"/> > > > value="com"/> > > > > . > > > > . > > > > > > > value="loaded(DetachedStateField=false)"/> > > > > > > > > > > Am I missing something in my configuration or is this just something that > > is > > not supported by Slice? If it's not supported, are there any recommended > > alternatives? > > > > Thanks, > > Richard. > > > > > > -- > *Rick Curtis* >
Slice and connection pools
Hi, Does Slice support using a connection pool? I was able to get the connection pool working when not using Slice with the following persistence-unit: org.apache.openjpa.persistence.PersistenceProviderImpl However, I got an error when attempting to use it in Slice, with the following: org.apache.openjpa.persistence.PersistenceProviderImpl . . Am I missing something in my configuration or is this just something that is not supported by Slice? If it's not supported, are there any recommended alternatives? Thanks, Richard.
Re: Slice closing EntityManager on named queries
Hi Pinaki, The named queries were already in JPQL format. Turning off the QuerySQLCache seems to have done the trick. Will this affect performance by not enabling that particular cache? I'll continue testing and report back if there are further issues. But so far it looks to have resolved the issue. Thanks! Richard.
Slice closing EntityManager on named queries
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 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 results = new LinkedHashSet(); 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(results); } Error Log: ... (1st time query is run)... 9 platform_slice TRACE [http-8080-1] openjpa.Runtime - Found datasource1: datasource 1730863804 from configuration. StoreContext: org.apache.openjpa.kernel.BrokerImpl@308bd98e 0 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 conf
Slice closing EntityManager on named queries
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 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 results = new LinkedHashSet(); 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(results); } Error Log: ... (1st time query is run)... 9 platform_slice TRACE [http-8080-1] openjpa.Runtime - Found datasource1: datasource 1730863804 from configuration. StoreContext: org.apache.openjpa.kernel.BrokerImpl@308bd98e 0 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. Sto