java - Cannot retrieve the id of the last inserted row in Oracle using Hibernate -
i'm using trigger fires before insert sequence generate id table in oracle 11g xe
here trigger
drop trigger googleplay.organization_code_generator; create or replace trigger googleplay.organization_code_generator before insert on googleplay.organizations referencing new new old old each row declare begin select organization_seq.nextval :new.code dual; exception when others -- consider logging error , re-raise raise; end organization_code_generator;
here sequence
drop sequence googleplay.organization_seq; create sequence googleplay.organization_seq start 41 maxvalue 99 minvalue 1 nocycle nocache noorder;
i want id using hibernate i'm using
session.persist(cashierorganization); session.flush(); cashierorganization = (organizations) session.merge(cashierorganization);
but 0 id suggestions ?
did try use custom generator id set trigger during insert? it's relative common situation when work oracle. try use this:
@id @generatedvalue(generator="triggergenerator") @genericgenerator(name="triggergenerator", strategy="package.to.my.custom.generator.triggerassignedidentitygenerator") private long id;
the triggerassignedidentitygenerator class implementing custom generator strategy , implementation shown in topic in hibernate forum:
hope help!
Comments
Post a Comment