[hibernate-dev] Problem with MappedSuperclass

Christian Beikov christian.beikov at gmail.com
Tue Sep 4 11:14:27 EDT 2012


Hello!

I have a strange problem, which I don't have in my company related to 
the usage of mapped superclasses.
I have a base entity which encapsulates the id like this:

@MappedSuperclass
public abstract class SimpleEntity<T extends Serializable> implements 
Serializable {

     private static final long serialVersionUID = 1L;

     private T id;

     @Id
     @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = 
"idGenerator")
     @Column(name = "id", nullable = false, insertable = false, 
updatable = false)
     public T getId() {
         return id;
     }
     public void setId(T id) {
         this.id = id;
     }
}

A concrete class example looks like:

@Entity
@SequenceGenerator(name = "idGenerator", sequenceName = "my_entity_seq", 
initialValue = 1, allocationSize = 1)
public class MyEntity extends SimpleEntity<Integer> {

     private static final long serialVersionUID = 1L;

     private String name;

     public String getName() {
         return name;
     }
     public void setName(T name) {
         this.name = name;
     }
}

But when I try to start the application I get the following error:

Caused by: org.hibernate.AnnotationException: Unknown Id.generator: 
idGenerator
     at 
org.hibernate.cfg.BinderHelper.makeIdGenerator(BinderHelper.java:507)
     at 
org.hibernate.cfg.AnnotationBinder.processId(AnnotationBinder.java:2126)
     at 
org.hibernate.cfg.AnnotationBinder.processElementAnnotations(AnnotationBinder.java:2038)
     at 
org.hibernate.cfg.AnnotationBinder.processIdPropertiesIfNotAlready(AnnotationBinder.java:765)
     at 
org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:684)
     at 
org.hibernate.cfg.Configuration$MetadataSourceQueue.processAnnotatedClassesQueue(Configuration.java:3406)
     at 
org.hibernate.cfg.Configuration$MetadataSourceQueue.processMetadata(Configuration.java:3360)
     at 
org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1334)
     at 
org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1724)
     at 
org.hibernate.ejb.EntityManagerFactoryImpl.<init>(EntityManagerFactoryImpl.java:84)
     at 
org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:904)
     ... 9 more

This is just a simple example, anyway I have a lot of mapped super 
classes in my app.
Any ideas what the cause of the error might be? The message is not 
really helpful, also it doesn't point out where the error occurred.

Regards,
Christian


More information about the hibernate-dev mailing list