Bug #52106 The named BrokerFactory "ndb" is not valid
Submitted: 16 Mar 2010 18:13 Modified: 8 Apr 2010 11:18
Reporter: Todd Farmer (OCA) Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Cluster: Cluster/J Severity:S1 (Critical)
Version:7.1.2-beta OS:Windows (XP)
Assigned to: Bernd Ocklin CPU Architecture:Any

[16 Mar 2010 18:13] Todd Farmer
Description:
This appears to be a regression, as I had a running simple JPA program based on the tutorial at:

http://ocklin.blogspot.com/2009/12/java-and-openjpa-for-mysql-cluster_14.html

I upgraded to 7.1.2 GPL Cluster because the custom build I had did not provide InnoDB, and this program immediately stops working, apparently refusing to load the BrokerFactory for NDB:

javax.persistence.PersistenceException: Provider error. Provider: org.apache.openjpa.persistence.PersistenceProviderImpl
	at javax.persistence.Persistence.createFactory(Persistence.java:175)
	at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:111)
	at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:65)
	at firstsimpletest.testInitialJPA(firstsimpletest.java:174)
	at firstsimpletest.main(firstsimpletest.java:25)
Caused by: <openjpa-1.2.2-r422266:898935 fatal user error> org.apache.openjpa.persistence.ArgumentException: Could not invoke the static newInstance method on the named factory class "<<openjpa-1.2.2-r422266:898935 fatal user error> org.apache.openjpa.util.UserException: The named BrokerFactory "ndb" is not valid.>".
	at org.apache.openjpa.kernel.Bootstrap.newBrokerFactory(Bootstrap.java:70)
	at org.apache.openjpa.persistence.PersistenceProviderImpl.getBrokerFactory(PersistenceProviderImpl.java:110)
	at org.apache.openjpa.persistence.PersistenceProviderImpl.createEntityManagerFactory(PersistenceProviderImpl.java:87)
	at org.apache.openjpa.persistence.PersistenceProviderImpl.createEntityManagerFactory(PersistenceProviderImpl.java:117)
	at org.apache.openjpa.persistence.PersistenceProviderImpl.createEntityManagerFactory(PersistenceProviderImpl.java:59)
	at javax.persistence.Persistence.createFactory(Persistence.java:171)
	... 4 more
Caused by: <openjpa-1.2.2-r422266:898935 fatal user error> org.apache.openjpa.persistence.ArgumentException: The named BrokerFactory "ndb" is not valid.
	at org.apache.openjpa.kernel.Bootstrap.getFactoryClass(Bootstrap.java:159)
	at org.apache.openjpa.kernel.Bootstrap.invokeFactory(Bootstrap.java:111)
	at org.apache.openjpa.kernel.Bootstrap.newBrokerFactory(Bootstrap.java:62)
	... 9 more
Caused by: java.lang.ClassNotFoundException: ndb
	at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
	at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
	at java.lang.Class.forName0(Native Method)
	at java.lang.Class.forName(Class.java:247)
	at org.apache.openjpa.kernel.Bootstrap.getFactoryClass(Bootstrap.java:157)
	... 11 more

How to repeat:
Try to start OpenJPA app using 7.1.2-beta.

Suggested fix:
No Exception.
[16 Mar 2010 19:06] Bernd Ocklin
Hi,

can you attach your example with persistence.xml and *.java?
[16 Mar 2010 19:09] Todd Farmer
Persistence file

Attachment: persistence.xml (text/xml), 782 bytes.

[16 Mar 2010 19:09] Todd Farmer
First test class

Attachment: JPAFish.java (text/x-java), 1.10 KiB.

[16 Mar 2010 19:10] Todd Farmer
Second test class

Attachment: JPAWine.java (text/x-java), 635 bytes.

[16 Mar 2010 19:10] Todd Farmer
Not part of test case directly, but providing anyways

Attachment: Fish.java (text/x-java), 569 bytes.

[16 Mar 2010 19:11] Todd Farmer
Test driver

Attachment: firstsimpletest.java (text/x-java), 6.24 KiB.

[16 Mar 2010 19:20] Todd Farmer
It's worth noting that the persistence.xml file is *identical* to what was provided on the blog, with the following changes:

1.  Pretty-formatted with indentation
2.  Changed <property...> tag to XML-compliant <property ... /> tab because SAX complained.
3.  Removed "xsi" attribute from header once SAX complained.
4.  Removed "type" attribute from persistence-unit tag, because SAX complained
5.  Eliminated whitespace from inside <provider> tag
6.  Changed class names to reflect test class names implemented.

It's also worth noting that this exact same code and persistence.xml file worked as expected using the previous version provided, and that the BrokerFactory is configured as described both in the blog entry and the manual:

"To activate ClusterJPA, the property named openjpa.BrokerFactory must have the value ndb. "

http://dev.mysql.com/doc/ndbapi/en/mccj-using-jpa.html
[16 Mar 2010 19:25] Todd Farmer
Oh, and I changed the port number for the JDBC connection.
[16 Mar 2010 19:33] Craig Russell
The root cause is this: Caused by: java.lang.ClassNotFoundException: ndb

The cause of this might be the META-INF/services/org.apache.openjpa.lib.conf.ProductDerivation which if missing would generate this error. This file needs to be packaged with the clusterjpa jar file and in the class path. The problem could be a simple build issue (regression).
[16 Mar 2010 19:46] Todd Farmer
That seems to be the case.  Using the cluster-jpa.jar from the custom build resolves the issue, and confirmed manually that there is no services directory in META-INF in the public GPL beta cluster-jpa.jar file.

This does raise the question, though, on why such a simple build failure with catastrophic results for all JPA use cases would not be caught in build tests?
[16 Mar 2010 19:48] Bernd Ocklin
How about your classpath?
[16 Mar 2010 19:51] Todd Farmer
As noted, changing the classpath (using Eclipse, so not being set at command-line, or I would provide it) to use the clusterjpa-7.1.2.beta.jar from the custom build solves the issue, while reverting back to the same .jar file obtained from the public beta download fails.

Examining the .jar file packaged in the public beta downloads will confirm this is caused by the problem Craig identified.
[16 Mar 2010 19:58] Bernd Ocklin
Ok, comments got crossed at last comment. 

Sources and release are okay. Builds for WIndows are screwed though. There are some initial build issues that we simply need to work on for GA. Good we have a rehearsal with this 7.1.2-beta to flush out last issues in the build process.
[22 Mar 2010 9:38] Bernd Ocklin
This fixed builds, too:

http://lists.mysql.com/commits/103887

Pushed to 7.1.3
[8 Apr 2010 11:18] Jon Stephens
Documented in the NDB-7.1.3 changelog as follows:

        The file
        META-INF/services/org.apache.openjpa.lib.conf.ProductDerivation
        was missing from the clusterjpa JAR file. This could cause
        setting openjpa.BrokerFactory to ndb to be rejected.

Closed.
[17 Jun 2012 0:47] Craig Russell
This issue also occurs with builds of mysql-5.5-cluster-7.2 up to 7.2.6. It has been fixed in 7.2.7.