Bug #57503 JpaCluster on Glassfish using persistence.xml: Can not connect to 192.168.56.101
Submitted: 17 Oct 2010 12:53 Modified: 19 Aug 2013 19:16
Reporter: Nicolas Seyvet Email Updates:
Status: Can't repeat Impact on me:
None 
Category:MySQL Cluster: Cluster/J Severity:S3 (Non-critical)
Version:mysql-5.1-telco-7.1 OS:Linux
Assigned to: CPU Architecture:Any
Tags: OpenJPA Cluster mysql-cluster 7.1.8

[17 Oct 2010 12:53] Nicolas Seyvet
Description:
Doing some prototyping with openJPA + JpaCluster + Sailfin 2 (based on glassfish 2.1) + JPA.

Using the following persistence.xml:
<persistence-unit name="BM" transaction-type="JTA">
        <provider>
            org.apache.openjpa.persistence.PersistenceProviderImpl
        </provider>
        <jta-data-source>jdbc/bm</jta-data-source>
        <class>persist.BigCompany</class>
        <class>persist.SmallEmployee</class>
        <properties>
            <property name="openjpa.BrokerFactory" value="ndb"/>
            <property name="openjpa.ndb.connectString" value="192.168.56.101:1186"/>
            <property name="openjpa.jdbc.SynchronizeMappings"
                      value="buildSchema(SchemaAction='add')"/>
            <property name="openjpa.ConnectionRetainMode" value="transaction"/>
            <property name="openjpa.ndb.database" value="bm"/>
            <property name="openjpa.ndb.connectVerbose" value="1"/>
            <property name="openjpa.DataCache" value="false"/>
            <property name="openjpa.ConnectionUserName" value="root"/>
            <property name="openjpa.ConnectionPassword" value="system"/>
        </properties>
    </persistence-unit>

Cluster-j seems to fail to connect to a data node:

Caused by: <openjpa-1.2.2-r422266:898935 nonfatal general error> org.apache.openjpa.persistence.PersistenceException: Error getting connection to cluster with properties {com.mysql.clusterj.connect.verbose=1, com.mysql.clusterj.connect.retries=4, com.mysql.clusterj.connect.delay=5, com.mysql.clusterj.connectstring=192.168.56.101:1186, com.mysql.clusterj.max.transactions=1024, com.mysql.clusterj.connect.timeout.before=30, com.mysql.clusterj.database=bm, com.mysql.clusterj.connect.timeout.after=20} Caused by com.mysql.clusterj.ClusterJDatastoreException:Datastore exception Return code: -1 error code: 0 message: .
	at org.apache.openjpa.kernel.AbstractBrokerFactory.newBroker(AbstractBrokerFactory.java:196)
	at org.apache.openjpa.kernel.DelegatingBrokerFactory.newBroker(DelegatingBrokerFactory.java:142)
	at org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:192)
	at org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:56)
	at com.sun.enterprise.util.EntityManagerWrapper._getDelegate(EntityManagerWrapper.java:326)
	at com.sun.enterprise.util.EntityManagerWrapper.persist(EntityManagerWrapper.java:440)
	at loader.MyLoader.createCompany(MyLoader.java:60)
	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 com.sun.enterprise.security.application.EJBSecurityManager.runMethod(EJBSecurityManager.java:1011)
	at com.sun.enterprise.security.SecurityUtil.invoke(SecurityUtil.java:175)
	at com.sun.ejb.containers.BaseContainer.invokeTargetBeanMethod(BaseContainer.java:2929)
	at com.sun.ejb.containers.BaseContainer.intercept(BaseContainer.java:4020)
	at com.sun.ejb.containers.WebServiceInvocationHandler.invoke(WebServiceInvocationHandler.java:190)
	... 63 more
Caused by: com.mysql.clusterj.ClusterJFatalException: Error getting connection to cluster with properties {com.mysql.clusterj.connect.verbose=1, com.mysql.clusterj.connect.retries=4, com.mysql.clusterj.connect.delay=5, com.mysql.clusterj.connectstring=192.168.56.101:1186, com.mysql.clusterj.max.transactions=1024, com.mysql.clusterj.connect.timeout.before=30, com.mysql.clusterj.database=bm, com.mysql.clusterj.connect.timeout.after=20} Caused by com.mysql.clusterj.ClusterJDatastoreException:Datastore exception Return code: -1 error code: 0 message: .
	at com.mysql.clusterj.core.SessionFactoryImpl.<init>(SessionFactoryImpl.java:145)
	at com.mysql.clusterj.core.SessionFactoryImpl.getSessionFactory(SessionFactoryImpl.java:108)
	at com.mysql.clusterj.core.SessionFactoryServiceImpl.getSessionFactory(SessionFactoryServiceImpl.java:36)
	at com.mysql.clusterj.core.SessionFactoryServiceImpl.getSessionFactory(SessionFactoryServiceImpl.java:27)
	at com.mysql.clusterj.ClusterJHelper.getSessionFactory(ClusterJHelper.java:61)
	at com.mysql.clusterj.ClusterJHelper.getSessionFactory(ClusterJHelper.java:46)
	at com.mysql.clusterj.openjpa.NdbOpenJPAConfigurationImpl.createSessionFactory(NdbOpenJPAConfigurationImpl.java:261)
	at com.mysql.clusterj.openjpa.NdbOpenJPAConfigurationImpl.getSessionFactory(NdbOpenJPAConfigurationImpl.java:228)
	at com.mysql.clusterj.openjpa.NdbOpenJPAConfigurationImpl.getSessionFactory(NdbOpenJPAConfigurationImpl.java:52)
	at com.mysql.clusterj.openjpa.NdbOpenJPAStoreManager.setContext(NdbOpenJPAStoreManager.java:99)
	at com.mysql.clusterj.openjpa.NdbOpenJPAStoreManager.setContext(NdbOpenJPAStoreManager.java:93)
	at org.apache.openjpa.kernel.DelegatingStoreManager.setContext(DelegatingStoreManager.java:78)
	at org.apache.openjpa.kernel.BrokerImpl.initialize(BrokerImpl.java:311)
	at org.apache.openjpa.kernel.AbstractBrokerFactory.initializeBroker(AbstractBrokerFactory.java:216)
	at org.apache.openjpa.kernel.AbstractBrokerFactory.newBroker(AbstractBrokerFactory.java:190)
	... 78 more
Caused by: com.mysql.clusterj.ClusterJDatastoreException: Datastore exception Return code: -1 error code: 0 message: .
	at com.mysql.clusterj.tie.ClusterConnectionImpl.throwError(ClusterConnectionImpl.java:143)
	at com.mysql.clusterj.tie.ClusterConnectionImpl.handleError(ClusterConnectionImpl.java:120)
	at com.mysql.clusterj.tie.ClusterConnectionImpl.waitUntilReady(ClusterConnectionImpl.java:113)
	at com.mysql.clusterj.core.SessionFactoryImpl.<init>(SessionFactoryImpl.java:143)
	... 92 more
|#]

in the ndb_mgm show I can see available mysqld(API) nodes:
-- NDB Cluster -- Management Client --
ndb_mgm> show
Connected to Management Server at: localhost:1186
Cluster Configuration
---------------------
[ndbd(NDB)]	2 node(s)
id=3	@127.0.0.1  (mysql-5.1.47 ndb-7.1.8, Nodegroup: 0, Master)
id=4	@127.0.0.1  (mysql-5.1.47 ndb-7.1.8, Nodegroup: 0)

[ndb_mgmd(MGM)]	1 node(s)
id=1	@127.0.0.1  (mysql-5.1.47 ndb-7.1.8)

[mysqld(API)]	4 node(s)
id=50	@127.0.0.1  (mysql-5.1.47 ndb-7.1.8)
id=51 (not connected, accepting connect from any host)
id=52 (not connected, accepting connect from any host)
id=53 (not connected, accepting connect from any host)

I am using the default config.ini:

[ndb_mgmd]
hostname=localhost
datadir=/home/baboune/ndb/one-cluster/ndb_data
id=1

[ndbd default]
noofreplicas=2
datadir=/home/baboune/ndb/one-cluster/ndb_data

[ndbd]
hostname=localhost
id=3

[ndbd]
hostname=localhost
id=4

[mysqld]
id=50

[mysqld]
id=51

[mysqld]
id=52

[mysqld]
id=53

And my.cnf:

[mysqld]
ndbcluster
datadir=/home/baboune/ndb/one-cluster/mysqld_data
basedir=/home/baboune/mysqlc

Note: if I remove the ndb parts in the persistence.xml then everything works as my data source points to a valid MySQL connection pool.

How to repeat:
Using above persistence.xml configuration deploy an application on a glassfish server.
[17 Oct 2010 12:54] Nicolas Seyvet
glassfish logs

Attachment: server_2.rar (application/octet-stream, text), 20.70 KiB.

[17 Oct 2010 12:56] Nicolas Seyvet
Some comments on my setup:
- Main machine using windows 7 64 bits running Glassfish
- Virtual machine running Ubuntu Maverick 32 bits + Mysql cluster
[17 Oct 2010 17:00] Nicolas Seyvet
Tried the exact same thing but with everything collocated on windows and I seem to get a link towards the DB:

Caused by: org.apache.openjpa.lib.jdbc.ReportingSQLException: Can't create table 'bm.bigcompany' (errno: 157) {stmnt 202688481 CREATE TABLE BIGCOMPANY (id BIGINT NOT NULL AUTO_INCREMENT, name VARCHAR(255), PRIMARY KEY (id)) TYPE = ndbcluster} [code=1005, state=HY000]
	at org.apache.openjpa.lib.jdbc.LoggingConnectionDecorator.wrap(LoggingConnectionDecorator.java:192)
	at org.apache.openjpa.lib.jdbc.LoggingConnectionDecorator.access$700(LoggingConnectionDecorator.java:57)
	at org.apache.openjpa.lib.jdbc.LoggingConnectionDecorator$LoggingConnection$LoggingStatement.executeUpdate(LoggingConnectionDecorator.java:762)
	at org.apache.openjpa.lib.jdbc.DelegatingStatement.executeUpdate(DelegatingStatement.java:114)
	at org.apache.openjpa.jdbc.schema.SchemaTool.executeSQL(SchemaTool.java:1191)
	at org.apache.openjpa.jdbc.schema.SchemaTool.createTable(SchemaTool.java:949)
	at org.apache.openjpa.jdbc.schema.SchemaTool.add(SchemaTool.java:526)
	at org.apache.openjpa.jdbc.schema.SchemaTool.add(SchemaTool.java:344)
	at org.apache.openjpa.jdbc.schema.SchemaTool.run(SchemaTool.java:321)
	at org.apache.openjpa.jdbc.meta.MappingTool.record(MappingTool.java:501)
	... 82 more

It is still not good but at least it appears to connect to the NDB API.

So there is some sort of bug going to an external NDB API (not localhost)?
[17 Oct 2010 18:20] Nicolas Seyvet
OK this is not the right place to put this.  I should have logged it in the forums.

Sorry
/Nicolas
[17 Oct 2010 20:55] Nicolas Seyvet
OK did some additional tests using my LINUX VM only.  I do think there is a bug.

Using the exact same configuration for GlassFish (except that when setting the connection pool I use localhost, and the following persistence.xml:
   <persistence-unit name="BM" transaction-type="JTA">
        <provider>
            org.apache.openjpa.persistence.PersistenceProviderImpl
        </provider>
        <jta-data-source>jdbc/bm</jta-data-source>
        <class>persist.BigCompany</class>
        <class>persist.SmallEmployee</class>
        <properties>
            <property name="openjpa.BrokerFactory" value="ndb"/>
            <property name="openjpa.ndb.connectString" value="localhost:1186"/>
            <property name="openjpa.jdbc.SynchronizeMappings"
                      value="buildSchema(SchemaAction='add')"/>
            <!--property name="openjpa.jdbc.DBDictionary" value="mysql(DriverVendor=mysql)"/-->
            <property name="openjpa.jdbc.DBDictionary" value="TableType=ndbcluster" />

            <property name="openjpa.ConnectionRetainMode" value="transaction"/>
            <property name="openjpa.ndb.database" value="bm"/>
            <property name="openjpa.ndb.connectVerbose" value="1"/>
            <property name="openjpa.DataCache" value="false"/>
            <property name="openjpa.ConnectionPassword" value=""/-->
        </properties>
    </persistence-unit>

Then I get this error

Caused by: <openjpa-1.2.2-r422266:898935 fatal general error> org.apache.openjpa.persistence.PersistenceException: This operation failed for some instances.  See the nested exceptions array for details.
	at org.apache.openjpa.kernel.BrokerImpl.throwNestedExceptions(BrokerImpl.java:2375)
	at org.apache.openjpa.kernel.BrokerImpl.flush(BrokerImpl.java:2069)
	at org.apache.openjpa.kernel.BrokerImpl.flushSafe(BrokerImpl.java:1927)
	at org.apache.openjpa.kernel.BrokerImpl.flush(BrokerImpl.java:1698)
	at org.apache.openjpa.kernel.StateManagerImpl.assignObjectId(StateManagerImpl.java:524)
	at org.apache.openjpa.kernel.StateManagerImpl.assignField(StateManagerImpl.java:609)
	at org.apache.openjpa.kernel.StateManagerImpl.beforeAccessField(StateManagerImpl.java:1495)
	at org.apache.openjpa.kernel.StateManagerImpl.accessingField(StateManagerImpl.java:1478)
	at persist.BigCompany.pcGetid(BigCompany.java)
	at persist.BigCompany.getId(BigCompany.java:51)
	at loader.MyLoader.createCompany(MyLoader.java:61)
	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:616)
	at com.sun.enterprise.security.application.EJBSecurityManager.runMethod(EJBSecurityManager.java:1011)
	at com.sun.enterprise.security.SecurityUtil.invoke(SecurityUtil.java:175)
	at com.sun.ejb.containers.BaseContainer.invokeTargetBeanMethod(BaseContainer.java:2929)
	at com.sun.ejb.containers.BaseContainer.intercept(BaseContainer.java:4020)
	at com.sun.ejb.containers.WebServiceInvocationHandler.invoke(WebServiceInvocationHandler.java:190)
	... 63 more
Caused by: <openjpa-1.2.2-r422266:898935 fatal general error> org.apache.openjpa.persistence.PersistenceException: The transaction has been rolled back.  See the nested exceptions for details on the errors that occurred.
	at org.apache.openjpa.kernel.BrokerImpl.newFlushException(BrokerImpl.java:2187)
	at org.apache.openjpa.kernel.BrokerImpl.flush(BrokerImpl.java:2029)
	... 81 more
Caused by: com.mysql.clusterj.ClusterJException: Error executing getInsertOperation on table SMALLEMPLOYEE. Caused by java.lang.RuntimeException:NdbOpenJPADomainTypeHandlerImpl.operationSetNonPKValues caught exception
	at com.mysql.clusterj.core.SessionImpl.insert(SessionImpl.java:291)
	at com.mysql.clusterj.openjpa.NdbOpenJPAStoreManager.flush(NdbOpenJPAStoreManager.java:367)
	at org.apache.openjpa.kernel.DelegatingStoreManager.flush(DelegatingStoreManager.java:130)
	... 82 more
Caused by: java.lang.RuntimeException: NdbOpenJPADomainTypeHandlerImpl.operationSetNonPKValues caught exception
	at com.mysql.clusterj.openjpa.NdbOpenJPADomainTypeHandlerImpl.operationSetNonPKValues(NdbOpenJPADomainTypeHandlerImpl.java:713)
	at com.mysql.clusterj.core.SessionImpl.insert(SessionImpl.java:277)
	... 84 more
Caused by: java.lang.NullPointerException
	at com.mysql.clusterj.openjpa.NdbOpenJPADomainFieldHandlerImpl$ObjectOperationHandlerRelationField.getLong(NdbOpenJPADomainFieldHandlerImpl.java:894)
	at com.mysql.clusterj.openjpa.NdbOpenJPADomainFieldHandlerImpl$5.operationSetValue(NdbOpenJPADomainFieldHandlerImpl.java:1000)
	at com.mysql.clusterj.core.metadata.AbstractDomainFieldHandlerImpl.operationSetValue(AbstractDomainFieldHandlerImpl.java:299)
	at com.mysql.clusterj.openjpa.NdbOpenJPADomainTypeHandlerImpl.operationSetNonPKValues(NdbOpenJPADomainTypeHandlerImpl.java:708)
	... 85 more
|#]

Both tables are created though... 

The entities are defined as such:

@Entity
@Table(name="SMALLEMPLOYEE")
public class SmallEmployee implements Serializable {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id = null;
    private String name = null;

    @ManyToOne
    @JoinColumn(name = "COMP_ID", nullable = false)
    private BigCompany company = null;

    public SmallEmployee() {
        
    }
   // getter and setters
   // [...]
}

And the BigCompany

@Entity
@Table(name="BIGCOMPANY")
public class BigCompany implements Serializable {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id = null;
    private String name = null;

    @OneToMany(cascade = CascadeType.ALL, mappedBy = "company", fetch = FetchType.EAGER)
    private Set<SmallEmployee> employees = new HashSet<SmallEmployee>();

    public BigCompany() {
        
    }

   // getter and setters
   // [...]

}

It seems there is one problem in how the different parameters are exchanged between the persistence.xml and the connection pool setup (data source) in glassfish.

Additionally, there might be  a problem with the @GeneratedValue(strategy = GenerationType.IDENTITY)...  As this works fine without NDB.
[23 Jul 2013 18:45] Sveta Smirnova
Thank you for the report.

Can you repeat same issue without Sailfin 2?
[14 Aug 2013 16:57] Nicolas Seyvet
Not using GlassFish anymore...

No environment to reproduce.
[19 Aug 2013 19:16] Sveta Smirnova
Thank you for the feedback.

Closed as "Can't repeat" according to last comment. Although I asked to repeat *without* Glassfish.