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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T18:29:33+00:00 2026-05-14T18:29:33+00:00

I have a ‘dog’ Entitiy with an @Id and a @TableGenerator … @TableGenerator(table =

  • 0

I have a ‘dog’ Entitiy with an @Id and a @TableGenerator

...
@TableGenerator(table = "seq", name = "dog_gen", pkColumnName = "seq_name", valueColumnName="seq_val")
@Id @GeneratedValue(strategy = GenerationType.TABLE, generator = "dog_gen")
private Long id;
...

Is there a way to reuse the same table generator (dog_gen) in other entity? I want to keep the same id sequence in two independent Entities, say

dog=1,
dog=2,
dog=3,
cat=4,
cat=5,
dog=6
and so on…

Both entities don’t share a common superclass to implement some kind of inheritance with the id property.

If I add the @GeneratedValue( generator=”dog_gen”) on my cat entity, omitting the @TableGenerator declaration throws an Exception saying it can’t find the generator when starting the context.

Caused by: org.hibernate.AnnotationException: Unknown Id.generator: dog_gen
at org.hibernate.cfg.BinderHelper.makeIdGenerator(BinderHelper.java:413)
at org.hibernate.cfg.AnnotationBinder.bindId(AnnotationBinder.java:1795)
at org.hibernate.cfg.AnnotationBinder.processElementAnnotations(AnnotationBinder.java:1229)
at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:733)
at org.hibernate.cfg.AnnotationConfiguration.processArtifactsOfType(AnnotationConfiguration.java:498)
at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:277) 
  • 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-14T18:29:33+00:00Added an answer on May 14, 2026 at 6:29 pm

    Indeed and this is not what I was expecting after reading the javadoc of @TableGenerator:

    This annotation defines a primary key generator that may be referenced by name when a generator element is specified for the GeneratedValue annotation. A table generator may be specified on the entity class or on the primary key field or property. The scope of the generator name is global to the persistence unit (across all generator types).

    Maybe I’m not interpreting things correctly (the section 9.1.38 of the JPA spec doesn’t tell us more) but I was expecting to be able to reference a generator name from another Entity in the @GeneratedValue.

    Anyway, the following seems to work. In the Dog entity:

    @TableGenerator(table = "myseq", name = "dog_gen", pkColumnName = "seq_name", 
          valueColumnName = "seq_val", pkColumnValue = "Dog", allocationSize = 1)
    @Id
    @GeneratedValue(strategy = GenerationType.TABLE, generator = "dog_gen")
    private Long id;
    

    And in the Cat, well, the same:

    @TableGenerator(table = "myseq", name = "dog_gen", pkColumnName = "seq_name", 
          valueColumnName = "seq_val", pkColumnValue = "Dog", allocationSize = 1)
    @Id
    @GeneratedValue(strategy = GenerationType.TABLE, generator = "dog_gen")
    private Long id;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

have 2 questions : A computer with 32-bit address uses 2-level page table (9
have written this little class, which generates a UUID every time an object of
Have a procedure which looks like Procedure TestProc(TVar1, TVar2 : variant); Begin TVar1 :=
Have done quite a bit of searching for a guide (of any substance) for
Have deployed numerous report parts which reference the same view however one of them
have a problem. At first look at this HTML <div id=map style=background-image: url(map.png); width:
Have a painfully simple blog Post creator, and I'm trying to check if the
Have an issue with marshall and unmarshall readers and writers. So here it is.
Have 2 tables in Access 2007, both lists of certain tasks to be accomplished.
have a nice day. I got problem when trying to create an image from

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.