0

The below code for Java works fine in Oracle-eclipselink-java, as we migrated the same to mariadb, we are facing the issue stated below.

Db sequence:

CREATE OR REPLACE SEQUENCE `com_seq` start with 370700 minvalue 1 maxvalue
9223372036854775806 increment by 1 cache 20 nocycle ENGINE=InnoDB

Java code/Entity class:

@Column(name = "ID")
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "com_seq")
@SequenceGenerator(name = "com_test_sample ", sequenceName = "com_seq", allocationSize=1)

private Integer id;

Note: Strategy = sequence or GenerationType.SEQUENCE (tried with both).

When we try with above coding and it's defined values we are getting below error:

Field 'ID' doesn't have a default value
Error Code: 1364
Call: INSERT INTO com_test_sample (ACTION, COMPLAINT_ID, TEXT_PARAMS, CREATE_TIMESTAMP, DELETE_REMARK, OVV_STATUS, PREV_OVV_STATUS, REMARK, VALUE, PERSON_ID, SUB_PERSON_ID) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
        bind => [DRAFT_STATUS_SET, 370703, null, 2022-10-11 19:37:38.22, null, DRAFT, null, null, null, 25071, 25071]
Query: InsertObjectQuery(de.wirthedv.OVV.complaintjournal.domain.ComplaintJournal@1f)
ahuemmer
  • 1,653
  • 9
  • 22
  • 29
Arun
  • 1
  • What is the database platform EclipseLink is using? If you don't know, turn on logging to fine/finest and it should show when it deploys/logs in. This level of logging might also show what it determines is set on your entity and why it isn't trying to pre-allocate a value from your sequence; first guess though is that you are not using the MariaDBPlatform and instead using a MySQLPlatform. Maria's main difference (I've been told) is it supports sequences while MySQL only had identity, which might explain there not being an attempt to read a sequence value. – Chris Oct 11 '22 at 15:27
  • You can specify the platform using the target-database persistence property (https://www.eclipse.org/eclipselink/documentation/2.5/jpa/extensions/p_target_database.htm ) and specify MariaDB , though I'm not sure what version it was added in. – Chris Oct 11 '22 at 15:33
  • GeneratedValue.generator should refer to sequence generator(!) name! (So `com_test_sample` in your case) – xerx593 Oct 12 '22 at 10:40
  • Chris, we are using do u suggest to use mariadb instead of mysql ? – Arun Oct 12 '22 at 17:04
  • @ xerx593, yes I have tried using the same generator name. @Column(name = "ID") @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "com_test_sample ") @SequenceGenerator(name = "com_test_sample ", sequenceName = "com_seq", allocationSize=1) – Arun Oct 12 '22 at 17:08
  • Today I have tested with GenerationType.SEQUENCE, GenerationType.AUTO, GenerationType.Table, GenerationType.Identity. For, GenerationType.SEQUENCE -- field id does not have a default value. – Arun Oct 12 '22 at 17:15
  • Includes seqeuncegenerator line as below @Column(name = "ID") @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "com_seq") @SequenceGenerator(name = "com_test_sample ", sequenceName = "com_seq", allocationSize=1) --------------------- For GenerationType.Auto, GenerationType.table -- commented sequencegenerator line as below @Column(name = "ID") @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "com_seq") #@SequenceGenerator(name = "com_test_sample ", sequenceName = "com_seq", allocationSize=1) – Arun Oct 12 '22 at 17:25
  • received error as Internal Exception: java.sql.SQLSyntaxErrorException: (conn=4344) Table 'dbname.sequence' doesn't exist Error Code: 1146 Call: UPDATE SEQUENCE SET SEQ_COUNT = SEQ_COUNT + ? WHERE SEQ_NAME = ? bind => [50, SEQ_GEN_TABLE] Query: DataModifyQuery(name="SEQ_GEN_TABLE" sql="UPDATE SEQUENCE SET SEQ_COUNT = SEQ_COUNT + ? WHERE SEQ_NAME = ?") javax.faces.FacesException: #{complaintEditView.createComplaint()}: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.6.4.v20160829-44060b6): org.eclipse.persistence.exceptions.DatabaseExceptio – Arun Oct 12 '22 at 17:25
  • As we got Table 'dbname.sequence' doesn't exist error: we created the table and started the server. but received the below mentioned error. CREATE TABLE ddname.`SEQUENCE` ( SEQ_NAME VARCHAR(50), SEQ_COUNT DECIMAL(38,0), CONSTRAINT PK_SEQUENCE PRIMARY KEY (SEQ_NAME), CONSTRAINT SYS_C0087791 CHECK ("SEQ_NAME" IS NOT NULL) ); CREATE UNIQUE INDEX PK_SEQUENCE ON A4PCCT.`SEQUENCE` (SEQ_NAME); – Arun Oct 12 '22 at 17:34
  • WARNING [http-nio-8080-exec-2] com.sun.faces.lifecycle.InvokeApplicationPhase.execute #{complaintEditView.createComplaint()}: Exception [EclipseLink-4011] (Eclipse Persistence Services - 2.6.4.v20160829-44060b6): org.eclipse.persistence.exceptions.DatabaseException Exception Description: Error preallocating sequence numbers. The sequence table information is not complete. – Arun Oct 12 '22 at 17:34
  • javax.faces.FacesException: #{complaintEditView.createComplaint()}: Exception [EclipseLink-4011] (Eclipse Persistence Services - 2.6.4.v20160829-44060b6): org.eclipse.persistence.exceptions.DatabaseException Exception Description: Error preallocating sequence numbers. The sequence table information is not complete. – Arun Oct 12 '22 at 17:34
  • We would like to know, whether eclipse link supports for maria db 10.5 RDS (aws) in the perspective of generating a sequence through database sequence object ? – Arun Oct 12 '22 at 17:38

0 Answers0