Why does Persistence.createEntityManagerFactory("transactions-optional") errors when appengine is deployed - google-app-engine

I have created an appengine which runs fine and returns records from my Google cloud SQL db in debug mode. When I deploy the appegine and run the endpoint it errors. And the error I get in the appengine log is:
Caused by: org.datanucleus.exceptions.NucleusUserException: There is no available StoreManager of type "jdbc". Make sure that you have put the relevant DataNucleus store plugin in your CLASSPATH and if defining a connection via JNDI or DataSource you also need to provide persistence property "datanucleus.storeManagerType".
Here is a list or the jars in war\WEB-INF\lib directory:
appengine-api-1.0-sdk-1.7.6
appengine-api-labs
appengine-endpoints
appengine-jsr107cache-1.7.6
asm-4.0
com.sun.tools.xjc_2.2.0
com.sun.xml.bind_2.2.0.v201004141950
datanucleus-api-jdo-3.1.3
datanucleus-api-jpa-3.1.3
datanucleus-appengine-2.1.2
datanucleus-core-3.1.3
eclipselink
eclipselink-jpa-modelgen_2.4.1.v20121003-ad44345
gcm-server
geronimo-jpa_2.0_spec-1.0
javax.activation_1.1.0.v201108011116
javax.mail_1.4.0.v201005080615
javax.persistence_2.0.4.v201112161009
javax.xml.bind_2.2.0.v201105210648
javax.xml.stream_1.0.1.v201004272200
jdo-api-3.0.1
json_simple-1.1
jsr107cache-1.1
jta-1.1
org.eclipse.persistence.jpars_2.4.1.v20121003-ad44345
Here is my persistence.xml:
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd" version="2.0">
<persistence-unit name="transactions-optional" transaction-type="RESOURCE_LOCAL">
<provider></provider>
<class>com.example.myapp.Class1</class>
<class>com.example.myapp.Class2</class>
<properties>
<property name="datanucleus.NontransactionalRead" value="true"/>
<property name="datanucleus.NontransactionalWrite" value="true"/>
<property name="javax.persistence.jdbc.driver" value="com.google.appengine.api.rdbms.AppEngineDriver"/>
<property name="javax.persistence.jdbc.url" value="jdbc:google:rdbms://something.com:someproj:someapp/somedb"/>
<property name="javax.persistence.jdbc.user" value=""/>
<property name="javax.persistence.jdbc.password" value=""/>
</properties>
</persistence-unit>
</persistence>
Using:
cloud sql
JPA
Datanucleous v2
SDK 1.7.6
Jre7
As it works fine in debug mode I dont understand what the problem might be as I am new to appengine. Please let me know if you need more information.
Thanks guys.

Make your mind up which JPA provider you're using ... for Cloud SQL (not AppEngine, so you don't need "datanucleus-appengine", nor do you need "datanucleus-api-jdo" either FWIW). You have DataNucleus JPA (version 3 actually, but omitting datanucleus-rdbms jar for some reason, yet CloudSQL needs it), and you have EclipseLink also. You then don't set the persistence provider in persistence.xml so leave it all to chance which one it tries to give you ... and it tries DataNucleus JPA but you haven't included the datanucleus-rdbms jar so you can't persist to an RDBMS without that.

Related

Config file Ignite discovery in zeppelin, config xml not working even after IgniteConfiguration bean is present

I am using zookeeper based discovery for ignite cluster and ignite nodes are getting properly connected.
When i am setting same config.xml file in zeppelin ignite interpreter in , I am not able to run the ignite. it fails with below exception.
It gives me below error on zepplin:
Failed to find configuration in: file:////tmp/shared.xml
Failed to find configuration in: file:////tmp/shared.xml
Exception details: please click this link
ignite_client.xml i am using:
<?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.xsd">
<bean class="org.apache.ignite.configuration.IgniteConfiguration">
<property name="clientMode" value="true"/>
<property name="peerClassLoadingEnabled" value="false"/>
<property name="discoverySpi">
<bean class="org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi">
<property name="ipFinder">
<bean class="org.apache.ignite.spi.discovery.tcp.ipfinder.zk.TcpDiscoveryZookeeperIpFinder">
<property name="zkConnectionString" value="zookeeper:2181"/>
</bean>
</property>
</bean>
</property>
<property name="cacheConfiguration">
<list>
<bean class="org.apache.ignite.configuration.CacheConfiguration">
<property name="name" value="testcache"/>
<property name="startSize" value="10"/>
</bean>
</list>
</property>
</bean>
I saw the Ignite code and found that its failing because spring bean is not found of type IgniteConfiguration, but in xml it is actually present as can be seen in shared xml above.
Analysis so far
Debugged zeppelin and Ignite code and verified correct xml file is passed to ignite.start
Verified even content of file tobe double sure by reading inputStream and file content is correct , inputStream is from org.springframework.beans.factory.xml.XmlBeanDefinitionReader#loadBeanDefinitions(org.springframework.core.io.support.EncodedResource)
On further debug verified that beanDefinitionMap in ApplicationContext contains IgniteConfiguration, attaching snapshot
Tried getting bean by name , it works ... instead of cfgMap = springCtx.getBeansOfType(cls); in org.apache.ignite.internal.util.spring.IgniteSpringHelperImpl#loadConfigurations(java.net.URL, java.lang.Class, java.lang.String...)
For sake of trial I used sprintContext.getBean(), assuming it would run, but its getting weired , I got below class cast exception
After analysis so far, only thing I can understand is some how IgniteConfiguration loaded by diff classloader is causing issue, but dont know why its happening
Debugged further and confirmed, it is because IgniteConfiguration loaded by different class loader, one loaded already was from sun.misc.Launcher.AppClassLoader#AppClassLoader and in sprinContext IgnitConfiguration bean present is loded by scala.reflect.internal.util.ScalaClassLoader and that is why the error "Failed to find configuration in: file:////tmp/shared.xml"
Logically I can think it as spark program is scala code and spring bean loaded at runtime that is why this mismatch
Is this normal ?
I tried your configuration and it works for me. Did you have another version of the file before? If so, I think it was not updated properly, because the only way to get this exception is having valid Spring XML file, but without IgniteConfiguration bean.
Are you sure you actually use the correct file? Can this be caused by the fact that you have it in /tmp folder?

playframework 2.X JPA to MSSQL Unable to build Hibernate SessionFactory

I want to using JPA connect to MSSQL,using sample computer-database-jpa can access h2 sql ,but when i change to mssql ,it's put a error message "PersistenceException: [PersistenceUnit: defaultPersistenceUnit] Unable to build Hibernate SessionFactory" who can help me thanks!
my application.conf
# Database configuration
# ~~~~~
# You can declare as many datasources as you want.
# By convention, the default datasource is named `default`
db.default.driver=net.sourceforge.jtds.jdbc.Driver
db.default.url="jdbc:jtds:sqlserver://127.0.0.1:1433;DatabaseName=TCGW;SelectMethod=cursor:sendStringAsUnicode=true"
db.default.user=qqqq
db.default.password=qqqq
#db.default.driver=org.h2.Driver
#db.default.url="jdbc:h2:mem:play"
db.default.jndiName=DefaultDS
applyEvolutions.default=true
hibernate.use_sql_comments=true
my persistence.xml
<persistence-unit name="defaultPersistenceUnit" >
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<non-jta-data-source>DefaultDS</non-jta-data-source>
<properties>
<!--
<property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect"/>
-->
<property name="hibernate.dialect" value="org.hibernate.dialect.SQLServerDialect"/>
</properties>
</persistence-unit>

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.

Cloud Foundry + JPA + Spring + EntityManager

I want to deploy a Web based WAR into CloudFoundry using a cloud datasource.
I have defined a bean like this:
<cloud:data-source id="dataSource"/>
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="persistenceUnitName" value="myPersistenceUnit" />
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.EclipseLinkJpaVendorAdapter">
<property name="showSql" value="true"/>
<property name="generateDdl" value="true"/>
</bean>
</property>
</bean>
</beans>
....but when i try to deploy I obtain a Java Agent exception :
Cannot apply class transformer without LoadTimeWeaver specified
But i can't specfy a Java Agent whithout uploading a jar instrument agent.....
Any solution??
I'm not that familiar with EclipseLink, so I'm not even sure that the weaver requirement comes from EclipseLink, BUT
One way of doing this would be to deploy your app as a standalone app (i.e. deploy your own tomcat around it), that way you can put the extra weaver jar in lib/.
Have a look at http://blog.cloudfoundry.org/2012/06/18/deploying-tomcat-7-using-the-standalone-framework/ and https://github.com/ericbottard/cloudfoundry-tomcat-7
Also, if you only have one DataSource, you can avoid using the cloudfoundry-specific <cloud:datasource /> namespace by just uploading your regular app and have Cloud Foundry auto reconfigure your app (info here: http://blog.springsource.org/2011/11/04/using-cloud-foundry-services-with-spring-part-2-auto-reconfiguration/) As a matter of fact, this may be the way to have EclipseLink work seamlessly on Cloud Foundry (my guess here)
And of course, there's also the option of switching to another provider that doesn't require class instrumentation, but that's a bit extreme.
Again, I'm not an Eclipse Link guru, so I may be missing something here...

JPA entity manager factory creation failing; JBoss, Hibernate and SQL Server

Running JBoss 5.1, with Hibernate as the JPA provider. Backed with SQL Server 2008.
I'm receiving an error at server startup, which is java.lang.ClassCastException: org.hibernate.dialect.SQLServerDialect cannot be cast to org.hibernate.dialect.Dialect. Pretty clear message, but I'm baffled as to the underlying cause. I have hibernate-core-3.5.1-Final.jar on the classpath, and the necessary class files are present.
This dialect setting was giving no error in the project when it was being used as a property being passed to a Spring AnnotationSessionFactoryBean, but I'm trying to refactor a piece to straight EJB/JPA. For what it's worth, here's my persistence config:
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
version="1.0">
<persistence-unit name="[my name here]">
<jta-data-source>java:jdbc/[my name here]</jta-data-source>
<properties>
<property name="hibernate.show_sql" value="true" />
<property name="hibernate.dialect" value="org.hibernate.dialect.SQLServerDialect"/>
<property name="hibernate.cache.use_query_cache" value="true" />
<property name="hibernate.cache.use_second_level_cache" value="true" />
<property name="hibernate.cache.provider_class" value="net.sf.ehcache.hibernate.EhCacheProvider" />
</properties>
</persistence-unit>
I hate these kind of "here's my config and my stacktrace" questions, but I've been poking around on this for an hour and a half and am failing to come up with any new ideas.
The ClassCastException is caused by having two copies of the javax.persistence APIs in your system. When running on JBoss, you are just not supposed to package persistence jar in your application. Remove all the persistence related jar's from your application and the exception should go away.

Resources