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 !

DataNucleus
  • 15,497
  • 3
  • 32
  • 37
Ricardo García
  • 325
  • 3
  • 14
  • What do you mean when you say "update the sequence"? Update is not applicable to sequences, at least not in Oracle. – Olaf Jun 16 '11 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 – Ricardo García Jun 17 '11 at 06:18

1 Answers1

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 .

Community
  • 1
  • 1
Olaf
  • 6,249
  • 1
  • 19
  • 37
  • 1
    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: ` <![CDATA[ SELECT sec_new_sequence.nextVal FROM dual ]]> ` 2. Execute the query in java code: `Query query = getSession().getNamedQuery("nextSequenceValue");` It control the sequence as a wrapper to manage in java. Thanks! – Ricardo García Jun 20 '11 at 11:03