Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7874177
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T02:44:14+00:00 2026-06-03T02:44:14+00:00

This is my second post about hibernate. Since I started using hibernate it has

  • 0

This is my second post about hibernate. Since I started using hibernate it has given more problems than the problems it has solved. It almost makes me feel like I should have stuck to plain old JDBC. Anyway,

Here is one of the problems I’m trying to battle.

My Sequence generator in the .hbm files looks as follows.

<id name="id" type="long" column="ID">
    <generator class="sequence">
        <param name="sequence">ADVENTURES_ID_SEQ</param>
        <param name="allocationSize">1</param>
        <param name="initialValue">17599</param>
    </generator>
</id>

Please note: initial value is 17599. This is because LAST_NUMBER in the oracle sequence is: 17599

CREATED         25-APR-12
LAST_DDL_TIME   25-APR-12
SEQUENCE_OWNER  ADVENTURE_ADMIN
SEQUENCE_NAME   ADVENTURES_ID_SEQ
MIN_VALUE       1
MAX_VALUE       9999999999999999999999999999
INCREMENT_BY    1
CYCLE_FLAG      N
ORDER_FLAG      N
CACHE_SIZE      20
LAST_NUMBER     17599

When I run the code I see the next sequence generated as 200, 201 in the Hibernate Debug statement.

DEBUG SQL - select ADVENTURES_ID_SEQ.nextval from dual
DEBUG SequenceGenerator - Sequence identifier generated: 201

I expected the nextval should have been 17600. Seems like the oracle sequence is not getting used at all.

What is wrong in my configuration and how to fix it. Any help is greatly appreciated.

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T02:44:17+00:00Added an answer on June 3, 2026 at 2:44 am

    Self Answer (Workaround): I’m still seeing the issue but for now I have a workaround. Since it worked for me I’m selecting the question as complete.

    I’m letting Oracle generate the nextId using Trigger:

    create or replace
    TRIGGER ADVENTURE_ADMIN.ADVENTURES_ID_TRIG 
    BEFORE INSERT ON ADVENTURE_ADMIN.ADVENTURES FOR EACH ROW
    WHEN (new.ID IS NULL)
    BEGIN
        SELECT ADVENTURES_ID_SEQ.NEXTVAL INTO :new.ID FROM DUAL;  
    END;
    

    Then I’m letting hibernate use the Oracle Trigger generated ID. There are two ways of doing this.

    First is by using Hibernate select. Disadvantage of this approach is you will need another column in the table with unique constraint which is used by the hibernate as a key to fetch the row. It doesn’t really work for me as I have tables with primary key as the only unique key.

    Second is by using TriggerAssignedIdentityGenerator created by Jean-Pol Landrain, Martin Zeltner. Source could be found here. This has enabled me to get around the problem of finding another unique key for the table.

    Following is how I’m using it:

    <id name="id" type="long" column="ID">
        <generator class="org.hibernate.id.TriggerAssignedIdentityGenerator" />
    </id>
    

    Please Note: Hibernate version you are using matters. I’m using 3.5.4. hibernate 3.6 didn’t work for me. JDBC and Oracle Driver version also matters. You can refer to the documentation in the source file for the same.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

UPDATE: First problem solved, second one described at the bottom of this post. UPDATE2:
Most questions revolving around the title of this post ask about making Hibernate, or
First, a thank you in advance. Second, this is my first post so apologies
This bit of code is taking almost a half second to execute. Could somebody
According to this post , I am using a data context per call, so
I came across this post , which reports the following interview question: Given two
In this post I wondered about cleaner code when internationalising an app. that leads
(NOTE: This question is not about escaping queries, it's about escaping results) I'm using
I'm watching this video post (by Jon Galloway and Jesse Liberty) about Building a
I'm now writing my first jQuery Plugin and i found this blog post about

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.