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

  • SEARCH
  • Home
  • 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 3315036
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T22:18:11+00:00 2026-05-17T22:18:11+00:00

I am using Java and Hibernate as ORM tool. Is there any way i

  • 0

I am using Java and Hibernate as ORM tool. Is there any way i can implement sequence in Java using Hibernate?

Currently I am using Oracle sequences to achieve this, but that is a very costly way as interaction with database increases.

  • 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-05-17T22:18:11+00:00Added an answer on May 17, 2026 at 10:18 pm

    It is actually a very easy thing to do:

    package mypackage;
    import org.hibernate.id.IdentifierGenerator;
    import org.hibernate.engine.SessionImplementor;
    import org.hibernate.HibernateException;
    
    import java.io.Serializable;
    import java.security.SecureRandom;
    import java.util.UUID;
    
    public class RandomIdentifierGenerator implements IdentifierGenerator {
    
      private final static SecureRandom sr = new SecureRandom();
    
      public Serializable generate(SessionImplementor sessionImplementor, Object o) throws HibernateException {
        long val = sr.nextLong();
        return Long.toString(Math.abs(val), Character.MAX_RADIX);
      }
    }
    

    IdentitfierGenerator is the hibernate interface you have to implement. The above example just generates a random id.

    In order to use this you have to set the generator to mypackage.RandomIdentifierGenerator

    Obviously this implementation lacks any guarantee of not generating the same id twice, this may or may not be important for the application you are writing.

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

Sidebar

Related Questions

I'm using Hibernate for ORM of my Java app to an Oracle database (not
I'm currently developping an application in java using Hibernate as a persistence manager and
Currently I'm using a session-per-request approach to manage Hibernate sessions in a Java web
i am using hibernate as ORM tool, and while loading the data from table
I convert the DB from Oracle to MySQL. I'm using both Java & Hibernate.
How do I map a CHAR(1) to a boolean using Hibernate for Java?
I am using Hibernate in a Java application to access my Database and it
I am using Hibernate 3.x, MySQL 4.1.20 with Java 1.6. I am mapping a
Using Java, how can I test that a URL is contactable, and returns a
I have been using Hibernate ORM, which is an implementation of the JPA specification

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.