Hi, forum followers.
In my Cuba project there’s an entity extending BaseLang IdEntity and I created a SQL procedure to perform the data migration, inserting records manually in the corresponding table and assigning the id value from a incremental numeric variable.
Here you are the entity class declaration:
@NamePattern("%s %s %s|tipMoviment,dtMoviment,partida")
@Table(name = "MAGATZEM_MOVIMENT")
@Entity(name = "magatzem_Moviment")
public class Moviment extends BaseLongIdEntity implements Creatable, Updatable, SoftDelete {
private static final long serialVersionUID = 8073284349450287765L;
@Column(name = "CREATE_TS")
protected Date createTs;
@Column(name = "CREATED_BY", length = 50)
protected String createdBy;
....
And the portion of SQL procedure code for inserting the values:
DECLARE @newrefmag varchar(20),
......
@idmovim bigint = 0,
.......
--Crear el registre a la taula MAGATZEM_MOVIMENT
--********* TAULA MAGATZEM_MOVIMENT **********
--Incrementar id moviment
SET @idmovim = @idmovim + 1
--Crear nou registre:
INSERT INTO MAGATZEM_MOVIMENT(ID, CREATE_TS, CREATED_BY, UPDATE_TS, UPDATED_BY, DELETE_TS, DELETED_BY, TIP_MOVIMENT, DT_MOVIMENT, PARTIDA_ID, TOT_UNITATS, CONCEPTE, ALBARA)
VALUES (@idmovim, SYSDATETIME(), 'admin', null, null, null, null, 'E', CASE WHEN @dtentrada IS NULL THEN SYSDATETIME() ELSE @dtentrada END, @uuidpartida, @totunit, ('Migració dades ' + @swrepas), null)
When finishing the data migration and trying to insert a new record from the application next error appears:
Platform details:
CUBA Platform version: 7.2.11
CUBA Studio plugin version: 15.3-202
IntelliJ version: CUBA Studio 2020.2
Database: MS SQL-SERVER 2008 R2
To solve the problem, I was thinking in alter manually the value of the corresponding sequence on database but I didn’t find the SEC_UN_{domain} table as framework documentation indicates for Ms Sql Server before 2012:
The implementation of the sequence generation mechanism depends on the DBMS type. Sequence parameters can also be managed directly in the database, but in different ways.
For HSQL, Microsoft SQL Server 2012+, PostgreSQL and Oracle each UniqueNumbersAPI sequence corresponds to a SEC_UN_{domain} sequence in the database.
For Microsoft SQL Server before 2012 each sequence corresponds to a SEC_UN_{domain} table with a primary key of IDENTITY type.
For MySQL sequences correspond to records in the SYS_SEQUENCE table.
Which is the right method to perform the data migration and update the sequence with the id of the last migrated record.
Thanks in advance.