jmix-projects / jmix-ui

DEPRECATED. Use https://github.com/jmix-framework/jmix
https://www.jmix.io
3 stars 7 forks source link

Exceptions when working with first inserted into table "long identity" entity #62

Closed alexbudarov closed 4 years ago

alexbudarov commented 4 years ago

Project: attached jfresh2.zip

Cousine:

@Table(name = "JFRESH2_COUSINE")
@Entity(name = "jfresh2_Cousine")
public class Cousine implements JmixEntity {
    private static final long serialVersionUID = -3957794063409391217L;

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "ID", nullable = false)
    private Long id;

    @InstanceName
    @NotNull
    @Column(name = "NAME", nullable = false, unique = true)
    private String name;

Dish:

@Table(name = "JFRESH2_DISH")
@Entity(name = "jfresh2_Dish")
public class Dish implements JmixEntity {
    private static final long serialVersionUID = 5560524045913505287L;

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "ID", nullable = false)
    private Long id;

    @InstanceName
    @NotNull
    @Column(name = "NAME", nullable = false)
    private String name;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "COUSINE_ID")
    private Cousine cousine;

Case number 1

Case number 2

org.hsqldb.HsqlException: integrity constraint violation: unique constraint or index violation; UC_JFRESH2_COUSINE_NAME table: JFRESH2_COUSINE at org.hsqldb.error.Error.error(Unknown Source) at org.hsqldb.Constraint.getException(Unknown Source) at org.hsqldb.index.IndexAVL.insert(Unknown Source) at org.hsqldb.persist.RowStoreAVL.indexRow(Unknown Source) at org.hsqldb.TransactionManager2PL.addInsertAction(Unknown Source) at org.hsqldb.Session.addInsertAction(Unknown Source) at org.hsqldb.Table.insertSingleRow(Unknown Source) at org.hsqldb.StatementDML.insertSingleRow(Unknown Source)



Looks like these problems occur only for first inserted object which has ID == 0 ?
knstvk commented 4 years ago

Looks like an HSQL-only issue. Try to set "start with 1" when defining identity column in the DB.

andreysubbotin commented 4 years ago

The problem relates to 0-ID handling in EclipseLink. As a result, CUBA generates an IDENTITY column that starts from 1. Sample CUBA script: ID int generated by default as identity(start with 1) not null

Jmix Studio issue: https://youtrack.haulmont.com/issue/JST-250