Hibernate + oracle sequence + trigger Hibernate + oracle sequence + trigger oracle oracle

Hibernate + oracle sequence + trigger


Reponse found at HIbernate issue with Oracle Trigger for generating id from a sequence

I need to adapt my trigger to run only if no ID is given:

CREATE OR REPLACE TRIGGER A_TRGBEFORE INSERTON A REFERENCING NEW AS New OLD AS OldFOR EACH ROWWHEN (New.IDS is null) -- (1)BEGIN  :new.IDS := A_SEQ.nextval;END A_TRG;/

(1) this line allow Hibernate to manually call A_SEQ.nextVal to set the ID and then bypass the trigger else Hibernate will get the nextval for uselessly because the trigger will always reset the ID calling nextval again


In your class B you have @GeneratedValue(generator = "preferenceSequence") which not defined in the example that you have, it should be @GeneratedValue(generator = "bSequence")

By default hibernate allocation size is 50 the B: IDS=50 seems to suggest the mapping is picking the wrong sequence.