|
If a sequence generator is used in an entity, who references a sequence in a table, which generates negative IDs the application will stuck in an infinite loop.
Problem analysis: org.hibernate.id.enhanced.NoopOptimizer.generate Uses a while loop to get values from a sequence: {{while ((value == null) || (value.lt(1L))) { value = callback.getNextValue(); }
}} ... return value.makeValue();
If sequence generates negative ids, the condition will always be satisfied, what will end in an infinite loop.
On Hibernate ORM 3.3 the sequence generation worked with negative seqences.
Some test code:
CREATE SEQUENCE SQ_NEGATIVE MINVALUE -99999999999999999999999999 MAXVALUE -1 INCREMENT BY -1 START WITH -51976995 CACHE 20 NOORDER NOCYCLE;
{{@Entity public class LoopEntity { @Id @GeneratedValue(generator = "objId", strategy = GenerationType.SEQUENCE) @SequenceGenerator(name = "objId", sequenceName = "sq_negative", allocationSize = 1) @Column(name = "ID", unique = true, nullable = false, insertable = true, updatable = true, precision = 22, scale = 0) private Long id; }
}}
|