DatastoreJDOPersistenceManagerFactory class not found exception when configuring JDO on Appengine - google-app-engine

I am trying to configure JDO on Appengine but every time I try to persist something I get an
java.lang.ClassNotFoundException: org.datanucleus.store.appengine.jdo.DatastoreJDOPersistenceManagerFactory
Searching for this error I only got that I could have an error in my jdoconfig.xml
But I explicitly declare that I want to use this class my jdoconfig.xml, which I posted below.
<?xml version="1.0" encoding="utf-8"?>
<jdoconfig xmlns="http://java.sun.com/xml/ns/jdo/jdoconfig"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://java.sun.com/xml/ns/jdo/jdoconfig">
<persistence-manager-factory name="transactions-optional">
<property name="javax.jdo.PersistenceManagerFactoryClass"
value="org.datanucleus.store.appengine.jdo.DatastoreJDOPersistenceManagerFactory"/>
<property name="javax.jdo.option.ConnectionURL" value="appengine"/>
<property name="javax.jdo.option.NontransactionalRead" value="true"/>
<property name="javax.jdo.option.NontransactionalWrite" value="true"/>
<property name="javax.jdo.option.RetainValues" value="true"/>
<property name="datanucleus.appengine.autoCreateDatastoreTxns" value="true"/>
</persistence-manager-factory>
</jdoconfig>

decide if you are using GAE JDO plugin v1.0 (JDO2.x) or GAE JDO plugin v2.0 (JDO3.0) which kinda decides which jars you have in the classpath, and hence what entries you put in your jdoconfig.xml

Related

Problems With Activiti OSGI and Blueprint

i try to use Activiti in KARAF OSGI with camel.
I copied some parts out of the service mix configuration.
<?xml version="1.0" encoding="UTF-8"?>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:camel="http://camel.apache.org/schema/blueprint"
xsi:schemaLocation="
http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
http://camel.apache.org/schema/blueprint http://camel.apache.org/schema/blueprint/camel-blueprint.xsd"
xmlns:jpa="http://aries.apache.org/xmlns/jpa/v1.0.0"
xmlns:tx="http://aries.apache.org/xmlns/transactions/v1.0.0"
xmlns:ext="http://aries.apache.org/blueprint/xmlns/blueprint-ext/v1.0.0">
<ext:property-placeholder />
<!--
Setting up the process engine configuration, using an embedded H2 database together with our default Aries
transaction manager.
-->
<bean id="dataSource" class="org.h2.jdbcx.JdbcDataSource">
<property name="URL" value="jdbc:h2:~/activiti"/>
<property name="user" value="sa"/>
<property name="password" value=""/>
</bean>
<reference id="transactionManager" interface="javax.transaction.TransactionManager"/>
<bean id="configuration" class="org.activiti.engine.impl.cfg.JtaProcessEngineConfiguration" ext:field-injection="true">
<property name="databaseType" value="h2"/>
<property name="dataSource" ref="dataSource"/>
<property name="transactionManager" ref="transactionManager"/>
<property name="databaseSchemaUpdate" value="true"/>
<property name="transactionsExternallyManaged" value="true" />
<property name="defaultCamelContext" value="defaultContext"/>
</bean>
<!--
Set up the custom resolver implementation to ease integration with Camel routes
-->
<bean id="resolver" class="de.myproject.CamelAwareELResolver"/>
<reference-list availability="optional" interface="org.activiti.camel.ContextProvider">
<reference-listener ref="resolver" bind-method="addContextProvider" unbind-method="removeContextProvider" />
</reference-list>
<reference-list availability="optional" interface="org.activiti.engine.delegate.JavaDelegate">
<reference-listener ref="resolver" bind-method="bindService" unbind-method="unbindService" />
</reference-list>
<!--
Set up the Activiti process engine itself
-->
<bean id="processEngineFactory" class="org.activiti.osgi.blueprint.ProcessEngineFactoryWithELResolver" init-method="init" destroy-method="destroy">
<property name="processEngineConfiguration" ref="configuration"/>
<property name="bundle" ref="blueprintBundle"/>
<property name="blueprintELResolver" ref="resolver" />
</bean>
<bean id="processEngine" factory-ref="processEngineFactory" factory-method="getObject"/>
<bean id="runtimeService" factory-ref="processEngine" factory-method="getRuntimeService" />
<!--
Register the ProcessEngine and RuntimeService as OSGi services to allow other bundles to use them
-->
<service ref="processEngine" interface="org.activiti.engine.ProcessEngine"/>
<service ref="runtimeService" interface="org.activiti.engine.RuntimeService"/>
<bean id="routeBuilder" class="de.myproject.bpmn.BpmnRestRouteBuilder"/>
<camelContext id="clientContext" trace="false" xmlns="http://camel.apache.org/schema/blueprint">
<routeBuilder ref="routeBuilder" />
<route id="entryPointClient">
<from uri="vm:client_queue"/>
<to uri="jobsbpmn://bpmn"/>
</route>
</camelContext>
I can deploy the bundle without problems in the container. When i trigger a workflow with a camel module i get those exception:
2016-11-08 11:56:43,569 | ERROR | m://client_queue | JobsBpmnProducer
| 45 - jobs-logging - 1.0.0 | No Processdefinition found with this
Identifier ActivitiException: Expecting a
SpringProcessEngineConfiguration for the Activiti Camel module.
ClassCastException:
org.activiti.engine.impl.cfg.JtaProcessEngineConfiguration cannot be
cast to org.activiti.spring.SpringProcessEngineConfiguration**
How can i deploy a OSGI conform Processengine using spring to get Camel to work?
This problem might be fixed in the Activity code already.
See https://github.com/Activiti/Activiti/pull/519
Can you try with the newest Activitiy version?

Database Configuration In Spring As Well As Hibernate config files

I am a newbie to Spring and Hibernate.And while browsing through projects, I found database details like connection-url, username, password in both hibernate and spring xml config files.
I need to understand why we do so ?
Yes. If you using both Hibernate and Spring then you can also try like that.
You need both hibernate.cfg.xml for hibernate and ApplicationContext.xml for spring.
do like this, at first create your hibernate.cfg.xml.
i.e
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<!-- Database connection settings -->
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://localhost:3306/country</property>
<property name="connection.username">root</property>
<property name="connection.password">password</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="show_sql">false</property>
<property name="hibernate.current_session_context_class">thread</property>
<mapping class="com.hibernate.test" />
</session-factory>
</hibernate-configuration>
now create your ApplictionContext.xml,and add your hibernate.cfg.xml as properties in sessionFactory bean.
i.e
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
//package to scan for Annotated classes
<context:component-scan base-package="com.hibernate.spring" />
<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
//add and locate the hibernate.cfg.xml here
<property name="configLocation" value="classpath:hibernate.cfg.xml" />
</bean>
</beans>
by this you only need to call Application.xml,the hibernate.cfg.xml will automatically loaded.
You have two options.
You can have hibernate to manage your database connections or you can have Spring managing your connections.
When you have Hibernate managing your connections, you only need to tell Spring where hibernate configuration is. Sorry, I couldn't find very easily an example where Hibernate manages the connections and Spring only "using" hibernate.
The other option is to use Spring to manage your connections and hbm files/annotated entities.
Here is a snippet from Spring docs
<beans>
<bean id="myDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="org.hsqldb.jdbcDriver"/>
<property name="url" value="jdbc:hsqldb:hsql://localhost:9001"/>
<property name="username" value="sa"/>
<property name="password" value=""/>
</bean>
<bean id="mySessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="myDataSource"/>
<property name="mappingResources">
<list>
<value>product.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<value>
hibernate.dialect=org.hibernate.dialect.HSQLDialect
</value>
</property>
</bean>
</beans>
and here the full documentation
http://docs.spring.io/spring/docs/4.0.5.RELEASE/spring-framework-reference/htmlsingle/#orm-hibernate
Besides very specific problems, I can't a lot of differences on using either way but I would prefer to let Spring to manage my database connections and I can let Spring to deal transactions for example and have everything centralized in the same configuration file.

Datanucleus for google cloud sql, missing org.datanucleus.store.rdbms.RDBMSStoreManager

I'm trying to have datanucleus manage my google cloud sql tables within a Google App Engine java application.
Sadly, I receive the following error message:
org.datanucleus.exceptions.ClassNotResolvedException: Class
"org.datanucleus.store.rdbms.RDBMSStoreManager" was not found
in the CLASSPATH. Please check your specification and your CLASSPATH.
But let's go with order. Here's my jdoconfig.xml
<?xml version="1.0" encoding="utf-8"?>
<jdoconfig xmlns="http://java.sun.com/xml/ns/jdo/jdoconfig"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://java.sun.com/xml/ns/jdo/jdoconfig_3_0.xsd">
<persistence-manager-factory name="transactions-optional">
<property name="javax.jdo.PersistenceManagerFactoryClass"
value="org.datanucleus.api.jdo.JDOPersistenceManagerFactory" />
<property name="javax.jdo.option.ConnectionURL" value="appengine" />
<property name="javax.jdo.option.NontransactionalRead"
value="true" />
<property name="javax.jdo.option.NontransactionalWrite"
value="true" />
<property name="javax.jdo.option.RetainValues" value="true" />
<property name="datanucleus.appengine.autoCreateDatastoreTxns"
value="false" />
<prop key="javax.jdo.option.Multithreaded">true</prop>
<property name="datanucleus.cache.level2" value="true" />
<property name="datanucleus.cache.level2.type" value="none"/>
<property name="datanucleus.cache.level1.type" value="soft"/>
<property name="datanucleus.appengine.storageVersion"
value="READ_OWNED_CHILD_KEYS_FROM_PARENTS"/>
</persistence-manager-factory>
<persistence-manager-factory name="cloud-sql">
<property name="javax.jdo.PersistenceManagerFactoryClass"
value="org.datanucleus.api.jdo.JDOPersistenceManagerFactory" />
<property name="javax.jdo.option.ConnectionDriverName"
value="com.mysql.jdbc.GoogleDriver"/>
<property name="javax.jdo.option.ConnectionUserName" value="root"/>
<property name="datanucleus.autoCreateSchema" value="true"/>
</persistence-manager-factory>
</jdoconfig>
The two persistence-manager-factory declarations are one for the app engine non-relational datastore, one for google cloud sql.
The exception is thrown during construction of my SQLManager. The constructor states
#Inject
public SQLManager(final NamedQueryProvider queryProvider) {
super(queryProvider);
final Map<String, String> properties = new HashMap();
properties.put("javax.jdo.option.ConnectionURL", getConnectionUrl());
pmFactory = JDOHelper.getPersistenceManagerFactory(properties,
"cloud-sql");
}
You can say: you must miss a required jar from the classpath. However, in my pom.xml there is
<dependency>
<groupId>org.datanucleus</groupId>
<artifactId>datanucleus-accessplatform-jdo-rdbms</artifactId>
<version>3.3.4</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.datanucleus</groupId>
<artifactId>datanucleus-rdbms</artifactId>
<version>3.2.8</version>
</dependency>
The second artifact is actually unneeded, since is thrown in by the first. I've put it as an initial workaround, but it isn't working.
Anyone has something like an idea? There seems to be no documentation on datanucleus+jdo+cloud sql, but since I'm using it for accessing GAE datastore, I would like to reuse the same for cloud sql.
EDIT
Here's the relevant part of stack trace. Unfortunately, I'm unable to see in log in which jars app engine is looking for.
Class "org.datanucleus.store.rdbms.RDBMSStoreManager" was not found in the CLASSPATH.
Please check your specification and your CLASSPATH.
org.datanucleus.exceptions.ClassNotResolvedException: Class
"org.datanucleus.store.rdbms.RDBMSStoreManager" was not found in the CLASSPATH. Please
check your specification and your CLASSPATH.
at org.datanucleus.JDOClassLoaderResolver.classForName(JDOClassLoaderResolver.java:245)
at org.datanucleus.plugin.NonManagedPluginRegistry.createExecutableExtension(NonManagedPluginRegistry.java:679)
at org.datanucleus.plugin.PluginManager.createExecutableExtension(PluginManager.java:290)
at org.datanucleus.NucleusContext.createStoreManagerForProperties(NucleusContext.java:410)
at org.datanucleus.NucleusContext.initialise(NucleusContext.java:280)
at org.datanucleus.api.jdo.JDOPersistenceManagerFactory.freezeConfiguration(JDOPersistenceManagerFactory.java:591)
at org.datanucleus.api.jdo.JDOPersistenceManagerFactory.createPersistenceManagerFactory(JDOPersistenceManagerFactory.java:326)
at org.datanucleus.api.jdo.JDOPersistenceManagerFactory.getPersistenceManagerFactory(JDOPersistenceManagerFactory.java:256)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at com.google.appengine.tools.development.agent.runtime.Runtime.invoke(Runtime.java:115)
at javax.jdo.JDOHelper$16.run(JDOHelper.java:1965)
at java.security.AccessController.doPrivileged(Native Method)
at javax.jdo.JDOHelper.invoke(JDOHelper.java:1960)
at javax.jdo.JDOHelper.invokeGetPersistenceManagerFactoryOnImplementation(JDOHelper.java:1128)
at javax.jdo.JDOHelper.getPersistenceManagerFactory(JDOHelper.java:808)
at javax.jdo.JDOHelper.getPersistenceManagerFactory(JDOHelper.java:1093)
at javax.jdo.JDOHelper.getPersistenceManagerFactory(JDOHelper.java:960)
at com.mycompany.myproduct.mypackage.SQLManager.<init>(SQLManager.java:24)
The problem was a datanucleus jar versions mismatch.
I was using datanucleus-core, datanucleus-api-jdo etc at version 3.0.*, while datanucleus-rdbms 3.2. I've removed datanucleus-accessplatform-jdo-rdbms dependency, since I realized I didn't need all jars it brings in, and downgraded datanucleus-rdbms to 3.0.10 version. (Seems like datanucleus-appengine plugin is not yet supporting 3.2 series, that's why I preferred downgrade over upgrade).
Now I can connect to cloud sql fine.

No persistence providers available for "transactions-optional"

I'm having this error in my AppEngine project:
javax.persistence.PersistenceException: No persistence providers available for "transactions-optional" after trying the following discovered implementations: org.datanucleus.api.jpa.PersistenceProviderImpl
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:180)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:70)
jdoconfig.xml
<jdoconfig xmlns="http://java.sun.com/xml/ns/jdo/jdoconfig"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/jdo/jdoconfig http://java.sun.com/xml/ns/jdo/jdoconfig_3_0.xsd">
<persistence-manager-factory name="transactions-optional">
<property name="javax.jdo.PersistenceManagerFactoryClass"
value="org.datanucleus.api.jdo.PersistenceManagerFactoryClass"/>
<property name="javax.jdo.option.ConnectionURL" value="appengine"/>
<property name="javax.jdo.option.NontransactionalRead" value="true"/>
<property name="javax.jdo.option.NontransactionalWrite" value="true"/>
<property name="javax.jdo.option.RetainValues" value="true"/>
<property name="datanucleus.appengine.autoCreateDatastoreTxns" value="true"/>
<property name="datanucleus.appengine.singletonPMFForName" value="true"/>
</persistence-manager-factory>
</jdoconfig>
Its really weird since in my jdoconfig.xml there is this "transactions-optional"
Obviously JPA (which you use to get an EMF) doesn't use "jdoconfig.xml" (which is used by JDO). JPA uses "persistence.xml". Suggest you decide which API you're using before going further

Appengine jdoconfig.xml for local database

Has anyone successfully configured JDO datanucleus default to google app engine to work on a local database?
Why am I always getting an error in jdoconfig.xml when I have specified the property "datanucleus.storeManagerType" with value "rdbms." at the end part.
I tried googling but seems no luck.
Caused by: org.datanucleus.exceptions.NucleusUserException: There is no available StoreManager of type "rdbms". Please make sure you have specified "datanucleus.storeManagerType" correctly and that all relevant plugins are in the CLASSPATH
<persistence-manager-factory name="postgresql">
<property name="datanucleus.mapping.Schema" value="jdo"/>
<property name="javax.jdo.PersistenceManagerFactoryClass" value="org.datanucleus.store.appengine.jdo.DatastoreJDOPersistenceManagerFactory"/>
<property name="datanucleus.ConnectionDriverName" value="org.postgresql.Driver"/>
<property name="datanucleus.ConnectionURL" value="jdbc:postgresql://localhost:5432/jdo"/>
<property name="datanucleus.ConnectionUserName" value="jdo"/>
<property name="datanucleus.ConnectionPassword" value="jdo"/>
<property name="datanucleus.appengine.autoCreateDatastoreTxns" value="true"/>
<property name="datanucleus.autoStartMechanism" value="None"/>
<property name="datanucleus.autoCreateSchema" value="true"/>
<property name="datanucleus.validateTables" value="true"/>
<property name="datanucleus.validateConstraints" value="true"/>
<property name="datanucleus.validateColumns" value="true"/>
<property name="datanucleus.DetachAllOnCommit" value="true"/>
<property name="datanucleus.maxFetchDepth" value="1"/>
<property name="datanucleus.storeManagerType" value="rdbms"/>
code for PMF.java
private static final PersistenceManagerFactory pmfInstance =
JDOHelper.getPersistenceManagerFactory("postgresql");
I remember fixing this by including datanucleus-rdbms-X.Y.Z.jar in my WEB-INF/lib
When using another datastore aside from the default app-engine sdk's "transaction-optional" datastore, you need to use another web application container such as apache-tomcat or jetty in order for the rdbms driver classes (ie, postgresql.jar-org.postgresql.Driver, mysql.jar com.mysql.jdbc.Driver) to work since google app engine inhibits your application to use the java.net.socket.* which is used by the database drivers

Resources