Bug #51641 Can't use native auto_increment with ClusterJPA
Submitted: 2 Mar 2010 13:05 Modified: 1 Jun 2018 14:49
Reporter: Hartmut Holzgraefe Email Updates:
Status: Unsupported Impact on me:
None 
Category:MySQL Cluster: Cluster/J Severity:S3 (Non-critical)
Version:ndb-7.1.1 OS:Linux
Assigned to: CPU Architecture:Any

[2 Mar 2010 13:05] Hartmut Holzgraefe
Description:
I tried to use native auto_increment using 

  @Id 
  @GeneratedValue(strategy = GenerationType.IDENTITY)
  private long id;

which works fine when using openJPA with the standard MySQL backend,
when using ClusterJPA it fails with duplicate key errors though.

Looks as if ClusterJPA is not aware of the auto_increment
attribute of tables and so tries to insert 0 as the default
column value instead of fetching a new auto_incremenet value
by calling

  Ndb::getAutoIncrementValue(NdbDictionary::Table*,Uint32)

As a workaround GenerationType.AUTO can be used, but the generation of a new sequence value from the extra sequence table used for this by openJPA always seems to use SQL, so destroying any positive impact the ndbapi fast path may have on INSERT operations ...

How to repeat:
Try to use GenerationType.IDENTITY instead of .AUTO
[2 Mar 2010 18:00] Craig Russell
It is true that clusterj and clusterjpa currently do not support automatic generation of primary keys. This has been identified as a feature request with low priority.
[2 Mar 2010 18:04] Craig Russell
What we need to do is to change clusterj to identify that the column is auto-generated and then avoid setting the primary key value during insert. This is relatively straightforward.

What also needs to be done is to retrieve the key value after the insert, which is not as easy.
[24 Nov 2011 1:03] Rui Pereira
Is this corrected already?
How can Not using the Auto-Increment feature through JPA IDENTITY and having to use TABLE as a workaround makes this a non-critical request?
[19 Feb 2014 15:00] Mahmoud Ismail
any new updates on this issue?!