How to fix Unknown Entity Error on Dropwizard

A common beginner Error is: 

org.hibernate.MappingException: Unknown entity: my.package.core.MyClass

First make sure that your class has

@Entity
@Table(name = "demo")

Now check you Application class and go to the point where you create your Hibernate object.

private final HibernateBundle<AuthDemoConfig> hibernateBundle = 
new HibernateBundle<DemoConfig>(MyClass.class) {

    public DataSourceFactory getDataSourceFactory(
            AuthDemoConfig configuration) {
        return configuration.getDataSourceFactory();
    }

};

The problem appears when an entity is used that was not registered to Hibernate. To register you class add it to the parameters of your HibernateBundle initialisation. For Multiple classes it can look like this:

new HibernateBundle<DemoConfig>(MyClass.class, MyClass2.class) {...}

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert

Diese Website verwendet Akismet, um Spam zu reduzieren. Erfahre mehr darüber, wie deine Kommentardaten verarbeitet werden.