This week's book giveaway is in the Design and Architecture forum.
We're giving away four copies of Communication Patterns: A Guide for Developers and Architects and have Jacqui Read on-line!
See this thread for details.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

Oracle Sequence

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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...
 
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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).
 
Ranch Hand
Posts: 220
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi David,

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


Thanks
Benson
 
Why am I so drawn to cherry pie? I can't seem to stop. Save me tiny ad!
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic