Home > Blockchain >  Hibernate encountered a non-categorized annotated class
Hibernate encountered a non-categorized annotated class

Time:02-28

I am encountering this error:

org.hibernate.boot.model.source.internal.annotations.AnnotationMetadataSourceProcessorImpl - Encountered a non-categorized annotated class [com.propfinancing.marketing.model.Property]; ignoring

I don't understand what this means and searching around on the Internet is not giving me much help.

Here is my model class:

package com.propfinancing.marketing.model;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;

@Entity(name="Property")
@Table(name="property")
public class Property {
  @Id 
  @GeneratedValue
  @Column(name="id")
  private int id;

  public int getId() {
    return id;
  }

  public void setId(int id) {
    this.id = id;
  }  
}

I am trying to write a Spring-Hibernate webapp using a MariaDB backend database.

The first step I want to do is have Hibernate create the schema for me. I wrote a command line program to use SchemaExport to auto-create the tables. Here is what code:

package com.propfinancing.marketing.bin;

import com.propfinancing.marketing.model.Property;

import java.io.File;
import java.io.FileReader;
import java.util.EnumSet;
import java.util.Properties;
import org.hibernate.boot.MetadataSources;
import org.hibernate.boot.registry.StandardServiceRegistry;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.Configuration;
import org.hibernate.tool.hbm2ddl.SchemaExport;
import org.hibernate.tool.schema.TargetType;

public class CreateTables {
  public static void main(String[] args) 
  throws Exception {
    FileReader reader = new FileReader(Paths.CLASSES.getAbsolutePath() File.separator "application.properties");
    Properties properties = new Properties();
    properties.load(reader);
    properties.setProperty("hibernate.hbm2ddl.auto", "create");
    Configuration cfg = new Configuration();
    cfg.setProperties(properties);
    StandardServiceRegistryBuilder sb = new StandardServiceRegistryBuilder();
    sb.applySettings(cfg.getProperties());
    StandardServiceRegistry standardServiceRegistry = sb.build();                   
    MetadataSources metadataSources = new MetadataSources(standardServiceRegistry);
    metadataSources.addAnnotatedClass(Property.class);
    SchemaExport export = new SchemaExport();
    export.create(EnumSet.of(TargetType.DATABASE), metadataSources.buildMetadata());
  }
}

This is strange, I checked the source of org.hibernate.boot.model.source.internal.annotations.AnnotationMetadataSourceProcessorImpl and it seems to be generating the error from this method:

    private void categorizeAnnotatedClass(Class<?> annotatedClass, AttributeConverterManager attributeConverterManager) {
            final XClass xClass = reflectionManager.toXClass( annotatedClass );
            // categorize it, based on assumption it does not fall into multiple categories
            if ( xClass.isAnnotationPresent( Converter.class ) ) {
                //noinspection unchecked, rawtypes
                attributeConverterManager.addAttributeConverter( (Class<? extends AttributeConverter>) annotatedClass );
            }
            else if ( xClass.isAnnotationPresent( Entity.class )
                    || xClass.isAnnotationPresent( MappedSuperclass.class ) ) {
                xClasses.add( xClass );
            }
            else if ( xClass.isAnnotationPresent( Embeddable.class ) ) {
                xClasses.add( xClass );
            }
            else {
                log.debugf( "Encountered a non-categorized annotated class [%s]; ignoring", annotatedClass.getName() );
            }
        }

But, my persistent class is annotated with @Entity so it should be OK.

Any ideas why Hibernate does not like my model class?

CodePudding user response:

I figured it out. I am loading everything to Tomcat using a war file which gets automatically migrated to the Jakarta EE spec. Once I migrated my test files to Jakarta EE, everything worked fine.

  • Related