I have the follwoing sequence defined in oracle:
CREATE SEQUENCE MySequence
MINVALUE 65536
MAXVALUE 4294967296
START WITH 65536
INCREMENT BY 1
CYCLE
NOCACHE
ORDER;
I wonder how can I access this via Hibernate (the next value each time i request) ? (via JDBC i have used getGEnerateKeys)
I need the id before I use it on another entity that needs to be persisted.
Thanks
For Oracle you should use GenerationType.SEQUENCE
Edit: sequencename updated
Edit: refer to your comment:
Your requirement sounds like composit/embedded id (using multiple columns as primary key) using sequence. but unfortunately both solution doesnt support sequence generator. So far I can say;
*You can create a native query via hibernate and append to index number using ‘
select mySequence.nextval from dual.*Or you can create an oracle view for that with the new column which is showing sequence + index via subquery.
*This one very experimental and I didnt try but you can use @formula annotation. Example here.