Bug #69815 MySql Cluster OpenJpa extension does not support @MappedSuperclass
Submitted: 22 Jul 2013 21:16 Modified: 18 May 2018 20:41
Reporter: Serdyn du Toit Email Updates:
Status: Won't fix Impact on me:
None 
Category:MySQL Cluster: Cluster/J Severity:S4 (Feature request)
Version:7.3.2 OS:Microsoft Windows (Windows 8)
Assigned to: CPU Architecture:Any
Tags: openjpa
Triage: Needs Triage: D5 (Feature request)

[22 Jul 2013 21:16] Serdyn du Toit
Description:
MySql Cluster's extension to OpenJpa does not support the use of @MappedSuperclass, so its impossible to do object-relational-mapping of fields across a class hierarchy.

How to repeat:
Try and persist a @MappedSuperclass class hierarchy with OpenJpa and MySql Cluster.

Suggested fix:
Comment the error from NdbOpenJPADomainTypeHandlerImpl as here:

//        if (classMapping.getPCSuperclass() != null) {
//            // persistent subclasses are not supported
//            message = local.message("ERR_Subclass", this.describedType);
//            setUnsupported(message);
//        }

My limited testing has proved that this doesn't result in an error and that OpenJpa tells the user of any misconfiguration (eg a @MappedSuperclass that isn't mentioned in persistence.xml and vica versa).

I think the original programmer might just have supported only @Entity classes as more advanced functionality was just as yet untested.  Still, maybe Oracle's probably more mature tests catches something which my limited testing hasn't detected. But in principle - JDBC shouldn't really care about how data is structured in the client's implementation.
[23 Jul 2013 18:20] Sveta Smirnova
test case

Attachment: bug69815.tar (application/x-tar, text), 10.00 KiB.

[23 Jul 2013 18:21] Sveta Smirnova
Thank you for the report.

I was able to use MappedSuperClass: see test case attached.

Table created as:

CREATE  TABLE `test_table` (    `id` INT NOT NULL ,    `name` VARCHAR(45) NULL ,    PRIMARY KEY (`id`) )  ENGINE = ndbcluster;

INSERT INTO `test_table` (`id`, `name`) VALUES (1, 'test');

Please check my test case and if you mean different use case, provide your own test case.
[23 Jul 2013 19:49] Serdyn du Toit
@MappedSuperclass is a Jpa annotation so I was referring to its use with OpenJpa.  Ie as a superclass to something annotated with the Jpa @Entity annotation.  I haven't tried mapping a class hierarchy with ClusterJ myself - but happy if that works.

I'll upload a test - give me a hour or two and many thanks for the help :)
[23 Jul 2013 21:49] Serdyn du Toit
To clarify after looking again - @MappedSuperclass should be used and UPDATEs should not be seen in the MySql general log.  Ie it should be communicated directly to Ndb nodes and not to MySql Cluster.  (The @MappedSuperclass annotation works - it should just be communicated using Ndb and not Jdbc)

The reason its using Jdbc is due to this INFO-level error:
INFO: New domain type code.TestDataBean is not known to be supported because Class code.TestDataBean is not supported.
Class class code.TestDataBean is a persistent subclass and is not supported.;

HOWEVER - on trying to implement a testcase I'm not seeing idempotent behavior.

1. In one project:
955  testdb  ERROR  [main] openjpa.Enhance - The identity field defined in the code.shared.DataBean Embeddable is not supported. 
And then in the general log:
*************************** 65. row ***************************
  event_time: 2013-07-23 23:34:16
   user_host: root[root] @ localhost [127.0.0.1]
   thread_id: 705
   server_id: 0
command_type: Query
    argument: UPDATE OPENJPA_SEQUENCE_TABLE SET SEQUENCE_VALUE = 3851 WHERE ID =
 0 AND SEQUENCE_VALUE = 3801
*************************** 66. row ***************************

2. In another project:
INFO: New domain type com.d6.core.util.dao.testobjects.TestDataBean is not known to be supported because Class com.d6.core.util.dao.testobjects.TestDataBean is not supported.
For class java.lang.Class, table testdatabean is not a cluster table.;

Even though I do use the NDBCLUSTER engine.

Will re-investigate the reason for lack of idempotency and feedback.
[24 Jul 2013 8:44] Serdyn du Toit
Okay, those seem to be valid errors - so my quick hack which I suggested as a fix is not sufficient.

Example @MappedSuperclass implementation using OpenJpa attached.

This is a feature request, so ignore if Oracle doesn't think its important enough.  I'm going to try and fix this in my own project, but the solution is just going to have to be more complex than I initially thought.
[24 Jul 2013 8:45] Serdyn du Toit
Example OpenJpa @MappedSuperclass usage

Attachment: sandbox-mysqlc19-2.zip (application/x-zip-compressed, text), 15.83 KiB.

[2 Nov 2013 12:36] Sveta Smirnova
Thank you for the test case.

Verified as described:

2116  testdb  ERROR  [main] openjpa.Enhance - The identity field defined in the code.shared.DataBean Embeddable is not supported. 

But I had to change code/shared/IDataBean.java to get it work:

$ cat code/shared/IDataBean.java 
package code.shared;

import com.mysql.clusterj.annotation.PersistenceCapable;
import com.mysql.clusterj.annotation.PrimaryKey;

@PersistenceCapable(table = "data_bean")
public interface IDataBean<DATABEAN extends IDataBean<DATABEAN>> {
}
[18 May 2018 20:41] Lakshmi Narayanan Sreethar
Posted by developer:
 
ClusterJPA is no more. RIP!