• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Oracle Sequence

 
Bob Ciazoratione
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
Is there a way to tell Hibernate which sequence to use?

My POJO class has following ID:
<id
name="formulierId"
type="java.lang.Long"
column="FORMULIER_ID"
>
<generator class="native" />
</id>

And Hibernate generates the following SQL log when preparing this insert:
"Hibernate: select hibernate_sequence.nextval from dual"

The problem is that I want to use a specific sequence for this table and not the 'hibernate_sequence'. Is there a way to do this?

Thanx in advance,

Stijn
 
Bob Ciazoratione
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry guys,
Solved it by using:
<id
name="formulierId"
type="java.lang.Long"
column="FORMULIER_ID"
>
<generator class="sequence">
<param name="sequence">SEQ_SJUSTIF_FORMULIER_ID</param>
</generator>
</id>

Thanx anyway...
 
David Harkness
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From [url=]section 5.1.4.4[/url] of the Hibernate documentation, use the sequence generator type and provide a sequence name parameter.[ Beat me to it. ]
[ March 30, 2005: Message edited by: David Harkness ]
 
Bob Ciazoratione
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When I try to perform the session.save(obj) operation, the Hibernate log only shows: 'Hibernate: select SEQ_SJUSTIF_FORMULIER_ID.nextval from dual' but no insert statement. (and of cources, no insert is executed...).
Any idea why this occurs?

Thanx,
S.
 
David Harkness
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First, it's better to start a new topic for a new question. While this is related in that you use an ID generator when creating new objects, this problem would occur regardless of the generator type.

Saving and updating objects only registers them with the Session's unit of work. You must flush() the Session to make it execute the SQL statements to persist the changes in the database. Then you must commit() the Transaction you began at the start.

If you didn't explicitely begin() a transaction, Hibernate should have begun one for you. I use a framework called Spring that does all the transaction work in my application based on method tags, so I don't know if Hibernate will do this automatically, but I do know that you must tell Hibernate to either commit() or rollback() a Transaction to make your flush()ed changes permanent or undo them.

Once you've done all that, you can close() the Session or continue using a single one (preferably the former).
 
Benson Fung
Ranch Hand
Posts: 220
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi David,

DO I need to create the sequence person_id_sequence generator in oracle?


Thanks
Benson
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic