3

I need help related to Hibernate Generator Sequence.

Is it possible to manage with Hibernate java class a sequence defined in DB (Oracle) mapped by hibernate hbm file ?

I mean, update the sequence manually from java mapped class to generate a composite sequence.

Thanks !

2
  • What do you mean when you say "update the sequence"? Update is not applicable to sequences, at least not in Oracle. Commented Jun 16, 2011 at 12:52
  • Sorry, update the sequence, I mean to use the sequence (next, current, etc... ) defined in oracle DB via hibernate. It's possible to map a sequence (annotations, hbm.xml... ), without any relation to an POJO (in hibernate cfg file for example), and use it wherever I need ? thanks Commented Jun 17, 2011 at 6:18

1 Answer 1

1

To access a sequence via Hibernate you can use a named query. For example, consider following links: define named query in orm.xml with jpa and hibernate and http://www.coderanch.com/t/218082/ORM/java/Getting-sequence-hibernate .

Sign up to request clarification or add additional context in comments.

1 Comment

hi! I've tried this workaround and it worked as I want. This is what I finally did: 1. Create de query in *.hbm.xml mapping file from Entity: <sql-query name="nextSequenceValue"> <![CDATA[ SELECT sec_new_sequence.nextVal FROM dual ]]> </sql-query> 2. Execute the query in java code: Query query = getSession().getNamedQuery("nextSequenceValue"); It control the sequence as a wrapper to manage in java. Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.