org.hibernate.AnnotationException: Unknown Id.generator: ID_GENERATOR

org.hibernate.AnnotationException: Unknown Id.generator: ID_GENERATOR

I'm trying to create a @GenericGenerator annotation at the package level so it can be used by all the entities in the package.

1) I have a package-info.java class with the annotation:

@org.hibernate.annotations.GenericGenerator(name = "ID_GENERATOR",                  strategy = "enhanced-sequence", parameters = {
    @org.hibernate.annotations.Parameter(name = "sequence_name", value = "JPWH_SEQUENCE"),
    @org.hibernate.annotations.Parameter(name = "initial_value", value = "1000") })
package com;

2) In that same package, I have an entity with the following attribute:

@Id
@GeneratedValue(generator = "ID_GENERATOR")
private Long id;

this is resulting in an exception "Unknown Id.generator: ID_GENERATOR". If I include the @GenericGenerator annotation in the entity class, it works fine. However, I want to move this to the package level so I can reuse it in other entities.

Any ideas where the disconnect could be?

Thanks!


you can change the entity code to this:

@Id
@SequenceGenerator(name="my_id_generator", sequenceName="ID_GENERATOR")
@GeneratedValue(generator="my_id_generator")
private Long id;

source: link

org.hibernate.AnnotationException: Unknown Id.generator, Try adding allocationSize=1 in @SequenceGenerator and strategy = GenerationType.Sequence in @GeneratedValue. Also I would check the  Stack Overflow for Teams is a private, secure spot for you and your coworkers to find and share information. Learn more org.hibernate.AnnotationException: Unknown Id.generator: GenreIdGenerator


I think that you make a design mistake. If you want a common thing between your model classes, use inheritance. You can create a AbstractEntity class which defines the id generator. And every classes of your model inherite from this abtract. It is a common pattern. You can also put the traditional common attributes created, createdBy, updated, updatedBy and why not an sysname. Using an hibernate id generator does not really have sense.

Bye

[SOLVED]hibernate.AnnotationException: Unknown Id.generator, Hits the following Unknown Id.generator exception. Caused by: org.hibernate.​AnnotationException: Unknown  org.hibernate.AnnotationException: Unknown Id.generator: increment. In order to cleanup and refactor some code I created a new workspace and also new project (s). My project setup is as follows: One core-project (Javaproject using Maven for dependency management) and two dynamic web projects (JSF) that both share code from the core project (similar setup to this SO-Post ).


I put the package-info file in a package and then populated it with sub-packages as so:

org.persistence
    package-info
org.persistence.someclasses
    PersistenceClass
org.persistennce.otherclasess
    OtherPersistenceClass

This worked with no other action for some hours. Then I added, changed and deleted some values in the cfg.file and this worked no more, until I added the line <mapping package="org.persistence"/>

Then it worked again. I found that answer here:

Using @GenericGenerator in a package level annotation

@GeneratedValue: Unknown Id.generator| JBoss.org Content , Думаю, что вы делаете ошибку дизайна. Если вам нужна общая вещь между вашими классами моделей, используйте наследование. Вы можете  Caused by: org.hibernate.AnnotationException: Unknown Id.generator: account__user__id__seq at org.hibernate.cfg.BinderHelper.makeIdGenerator(BinderHelper.java:413) at


GenericGenerator in package-info.java not working JPA, Session Factory could not be created.org.hibernate.AnnotationException: Unknown Id.generator: ID_GENERATOR If I apply @GenericGenerator on top on​  You can create a AbstractEntity class which defines the id generator. And every classes of your model inherite from this abtract. It is a common pattern. You can also put the traditional common attributes created, createdBy, updated, updatedBy and why not an sysname. Using an hibernate id generator does not really have sense. Bye


3. org.hibernate.AnnotationException: Unknown Id.generator This one is caused by a wrong entity mapping, and you might run into it during development. The reason for it is pretty simple, you reference an unknown sequence generator in your @GeneratedValue annotation, like in the following code snippet.


Caused by: org.hibernate.AnnotationException: Unknown Id.generator: account__user__id__seq at org.hibernate.cfg.BinderHelper.makeIdGenerator(BinderHelper.java:413) at