org.hibernate.AssertionFailure: The root entity needs to specify an identifier

Hibernate JIRA | Tom Coogan | 5 years ago
  1. 0

    Our model classes inherit their identifiers from a MappedSuperclass as follows: {code} @MappedSuperclass public abstract class GenericModel { protected Long id; @Id @GeneratedValue(generator="postgres-seq") @GenericGenerator(name="postgres-seq", strategy = "com.zzz.zzz.util.PostgresSequenceGenerator") @Column(name = "id", nullable = false) public Long getId() { return this.id; } public void setId(Long id) { this.id = id; } } @Entity @Table(name="users") public class User extends GenericModel { ... } {code} When building the metadata for these classes, the following AssertionFailure occurs: {noformat} org.hibernate.AssertionFailure: The root entity needs to specify an identifier at org.hibernate.metamodel.source.annotations.entity.RootEntitySourceImpl.getIdentifierSource(RootEntitySourceImpl.java:63) at org.hibernate.metamodel.source.binder.Binder.bindIdentifier(Binder.java:309) at org.hibernate.metamodel.source.binder.Binder.makeRootEntityBinding(Binder.java:183) at org.hibernate.metamodel.source.binder.Binder.createBasicEntityBinding(Binder.java:159) at org.hibernate.metamodel.source.binder.Binder.doCreateEntityBinding(Binder.java:147) at org.hibernate.metamodel.source.binder.Binder.createEntityBinding(Binder.java:132) at org.hibernate.metamodel.source.binder.Binder.processEntityHierarchy(Binder.java:108) at org.hibernate.metamodel.source.annotations.AnnotationMetadataSourceProcessorImpl.processMappingMetadata(AnnotationMetadataSourceProcessorImpl.java:134) at org.hibernate.metamodel.source.internal.MetadataImpl.bindMappingMetadata(MetadataImpl.java:195) at org.hibernate.metamodel.source.internal.MetadataImpl.<init>(MetadataImpl.java:165) at org.hibernate.metamodel.source.internal.MetadataBuilderImpl.buildMetadata(MetadataBuilderImpl.java:83) at org.hibernate.metamodel.MetadataSources.buildMetadata(MetadataSources.java:112) {noformat} It appears that this is happening because EntityClass is always instantiated with a null parent from EntityHierarchyBuilder.createEntityHierarchies(AnnotationBindingContext bindingContext) line 105: {code} EntityClass rootEntityClass = new EntityClass( rootClassInfo, null, defaultAccessType, hierarchyInheritanceType, bindingContext ); {code} and therefore EntityClass.findIdAnnotations(DotName idAnnotationType) never loops through the parent hierarchy to find the @Id annotation in the MappedSuperclass. This was working in Hibernate 3.6.*.

    Hibernate JIRA | 5 years ago | Tom Coogan
    org.hibernate.AssertionFailure: The root entity needs to specify an identifier
  2. 0

    Our model classes inherit their identifiers from a MappedSuperclass as follows: {code} @MappedSuperclass public abstract class GenericModel { protected Long id; @Id @GeneratedValue(generator="postgres-seq") @GenericGenerator(name="postgres-seq", strategy = "com.zzz.zzz.util.PostgresSequenceGenerator") @Column(name = "id", nullable = false) public Long getId() { return this.id; } public void setId(Long id) { this.id = id; } } @Entity @Table(name="users") public class User extends GenericModel { ... } {code} When building the metadata for these classes, the following AssertionFailure occurs: {noformat} org.hibernate.AssertionFailure: The root entity needs to specify an identifier at org.hibernate.metamodel.source.annotations.entity.RootEntitySourceImpl.getIdentifierSource(RootEntitySourceImpl.java:63) at org.hibernate.metamodel.source.binder.Binder.bindIdentifier(Binder.java:309) at org.hibernate.metamodel.source.binder.Binder.makeRootEntityBinding(Binder.java:183) at org.hibernate.metamodel.source.binder.Binder.createBasicEntityBinding(Binder.java:159) at org.hibernate.metamodel.source.binder.Binder.doCreateEntityBinding(Binder.java:147) at org.hibernate.metamodel.source.binder.Binder.createEntityBinding(Binder.java:132) at org.hibernate.metamodel.source.binder.Binder.processEntityHierarchy(Binder.java:108) at org.hibernate.metamodel.source.annotations.AnnotationMetadataSourceProcessorImpl.processMappingMetadata(AnnotationMetadataSourceProcessorImpl.java:134) at org.hibernate.metamodel.source.internal.MetadataImpl.bindMappingMetadata(MetadataImpl.java:195) at org.hibernate.metamodel.source.internal.MetadataImpl.<init>(MetadataImpl.java:165) at org.hibernate.metamodel.source.internal.MetadataBuilderImpl.buildMetadata(MetadataBuilderImpl.java:83) at org.hibernate.metamodel.MetadataSources.buildMetadata(MetadataSources.java:112) {noformat} It appears that this is happening because EntityClass is always instantiated with a null parent from EntityHierarchyBuilder.createEntityHierarchies(AnnotationBindingContext bindingContext) line 105: {code} EntityClass rootEntityClass = new EntityClass( rootClassInfo, null, defaultAccessType, hierarchyInheritanceType, bindingContext ); {code} and therefore EntityClass.findIdAnnotations(DotName idAnnotationType) never loops through the parent hierarchy to find the @Id annotation in the MappedSuperclass. This was working in Hibernate 3.6.*.

    Hibernate JIRA | 5 years ago | Tom Coogan
    org.hibernate.AssertionFailure: The root entity needs to specify an identifier
  3. 0

    Exception: Unable to determine collection owner identifier for orphan-delete processing

    Eclipse Bugzilla | 7 years ago | mtaal
    org.hibernate.AssertionFailure: Unable to determine collection owner identifier for orphan-delete processing
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    org.hibernate.AssertionFailure: null identifier in Hibernate @OneToMany relationship

    Stack Overflow | 3 years ago | Swapnil
    org.hibernate.AssertionFailure: null identifier
  6. 0

    [HHH-779] Assertion failure occured with Hibernate 3 saving objects - Hibernate JIRA

    atlassian.net | 1 year ago
    org.hibernate.AssertionFailure: null identifier

    Not finding the right solution?
    Take a tour to get the most out of Samebug.

    Tired of useless tips?

    Automated exception search integrated into your IDE

    Root Cause Analysis

    1. org.hibernate.AssertionFailure

      The root entity needs to specify an identifier

      at org.hibernate.metamodel.source.annotations.entity.RootEntitySourceImpl.getIdentifierSource()
    2. Hibernate
      MetadataSources.buildMetadata
      1. org.hibernate.metamodel.source.annotations.entity.RootEntitySourceImpl.getIdentifierSource(RootEntitySourceImpl.java:63)
      2. org.hibernate.metamodel.source.binder.Binder.bindIdentifier(Binder.java:309)
      3. org.hibernate.metamodel.source.binder.Binder.makeRootEntityBinding(Binder.java:183)
      4. org.hibernate.metamodel.source.binder.Binder.createBasicEntityBinding(Binder.java:159)
      5. org.hibernate.metamodel.source.binder.Binder.doCreateEntityBinding(Binder.java:147)
      6. org.hibernate.metamodel.source.binder.Binder.createEntityBinding(Binder.java:132)
      7. org.hibernate.metamodel.source.binder.Binder.processEntityHierarchy(Binder.java:108)
      8. org.hibernate.metamodel.source.annotations.AnnotationMetadataSourceProcessorImpl.processMappingMetadata(AnnotationMetadataSourceProcessorImpl.java:134)
      9. org.hibernate.metamodel.source.internal.MetadataImpl.bindMappingMetadata(MetadataImpl.java:195)
      10. org.hibernate.metamodel.source.internal.MetadataImpl.<init>(MetadataImpl.java:165)
      11. org.hibernate.metamodel.source.internal.MetadataBuilderImpl.buildMetadata(MetadataBuilderImpl.java:83)
      12. org.hibernate.metamodel.MetadataSources.buildMetadata(MetadataSources.java:112)
      12 frames