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 6893677
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:41:20+00:00 2026-05-27T06:41:20+00:00

We tell Hibernate how to generate identifiers using the <generator> tag. For example: <generator

  • 0

We tell Hibernate how to generate identifiers using the <generator> tag. For example:

<generator class="sequence">
    <param name="sequence">person_id_sequence</param>
</generator>

I wish to use <generator class="assigned">. As per the documentation:

assigned

lets the application assign an identifier to the object before save() is called.

Is there a way to also configure a sequence generator that I can use to generate the identifiers that I will assign to my objects?

This is roughly what I wish to do:

Session session = ...;

// This will use the "sequence" generator:
Integer id = session.fictionalMethodThatGeneratesIdentifiers(Person.class);

Person person = new Person();
person.setId(id);
person.setName("Adam");

// This will use the "assigned" generator:
session.save(person);
  • 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-27T06:41:20+00:00Added an answer on May 27, 2026 at 6:41 am

    Yes (see below), but the obvious question is “why”?
    That’s a lot of work just to arrive at the same result.

    However, if you must…
    fictionalMethodThatGeneratesIdentifiers() would need to do what the hibernate sequence generator does, which is presumably whatever is required of your particular database to get the next sequence number.

    If you do this, note that the documentation says:

    The assigned generator makes Hibernate use unsaved-value=”undefined”.
    This forces Hibernate to go to the database to determine if an
    instance is transient or detached, unless there is a version or
    timestamp property, or you define Interceptor.isUnsaved().

    So, I’d suggest explicitly mapping unsaved-value to, say -1, and having your object initialize the id value to that, otherwise you are going to see a lot of extra overhead every time you try to save an instance.

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

Sidebar

Related Questions

I'm using hibernate with hbm2ddl.auto=update so that it'll automatically generate my oracle tables for
I'm using my uuid as following: @Id @GeneratedValue(generator = uuid) @GenericGenerator(name = uuid, strategy
I use Hibernate to generate my database automatically for testing, and I have some
I want to tell hibernate to give me a callback notification when a new
Can someone tell me how to accomplish this mapping using Fluent NHibernate? It's simply
I'm developing a web- application using NHibernate. Can you tell me how to write
Is there a way to tell Hibernate to wrap a column in a to_char
I am having trouble getting the right hibernate annotations to use on a Map
i am using the following approach to solve lazy initialization problem in hibernate. Please
There's an enterprise application using Java + Hibernate + PostgreSQL. Hibernate is configured via

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.