There are 2 applications : one is using Spring boot - 1.5.18.Release version, which has hibernate version as 5.0.12.Final
and another application is using Spring boot - 2.4.1 version which has hibernate version as 5.4.25.Final : https://search.maven.org/artifact/org.springframework.boot/spring-boot-dependencies/2.4.1/pom where we have used @SequenceGenerator(name = "sequenceGenerator", sequenceName = "ABCD_SEQ",allocationSize = 1),
The allocation size is required because the application does not starts up
while the allocation size was not required in first application.
Database sequence is created with "INCREMENT BY 1" and same oracle database is used by both applications.
The 2 applications uses many similar entity which is copied in another application/project.
But when inserting record from the second application where spring-boot is 2.4.1 , we are getting unique sequence generator issue.
When analysed, we found out that the first application(1.5.18.Release) is abruptly incrementing the sequence although it should increment it by 1, leaving lot of gaps in between, sometimes by 50, 100, etc. and when second application(2.4.1) tries to insert record , there is error of unique constraint.
Please help, exactly where to search for the root cause , or how the hibernate cache mechanism is used this case ?
One of the entity in first application (1.5.18.Release)
@Entity
@Table(name = "MERCURY_INSTANCE")
public class MercuryInstance implements Serializable {
@Id
@Column(name = "MERCURY_INSTANCE_KEY", nullable = false)
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "seqGen")
@SequenceGenerator(name = "seqGen", sequenceName = "MERCURY_INSTANCE_SEQ")
private Long mercuryInstanceKey;
@ManyToOne(cascade = CascadeType.DETACH, fetch = FetchType.LAZY)
@JoinColumn(name = "MERCURY_KEY", referencedColumnName = "MERCURY_KEY", nullable = false)
private MERCURY mercury;
@OneToOne(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
@JoinColumn(name = "MERCURY_INSTANCE_KEY", referencedColumnName = "MERCURY_INSTANCE_KEY", nullable = false)
private MercuryInstanceTechParams MercuryInstanceTechParams;
@ManyToMany(mappedBy = "mercuryGroupInstances")
private List<MercuryGroupInstance> MercuryGroupInstances;
@Column(name = "CREATED_DATE")
private Timestamp createdDte;
@Column(name = "CREATED_BY")
private String createdBy;
@Column(name = "UPDATED_DATE")
private Timestamp updatedDte;
@Column(name = "UPDATED_BY")
private String updatedBy;
/* getter and setters of above fields */
}
While another application(2.4.1) is similar, only difference is the sequence generator such as :
@Id
@Column(name = "MERCURY_INSTANCE_KEY", nullable = false)
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "seqGen")
@SequenceGenerator(name = "seqGen", sequenceName = "MERCURY_INSTANCE_SEQ", allocationSize = 1)
private Long mercuryInstanceKey;
and the database sequence is :
CREATE SEQUENCE "MERCURY_INSTANCE_SEQ" MINVALUE 1 MAXVALUE 9999999999999999999999999999 INCREMENT BY 1 START WITH 55 NOCACHE NOORDER NOCYCLE ;