rich
rich

Reputation: 19405

references an unknown entity: java.util.List

Can anyone suggest what I'm missing here? Error occurs on starting a dropwizard application.

The error:

web_1       | Exception in thread "main" org.hibernate.AnnotationException: @OneToOne or @ManyToOne on Resource.coordinates references an unknown entity: java.util.List
web_1       |   at org.hibernate.cfg.ToOneFkSecondPass.doSecondPass(ToOneFkSecondPass.java:97)
web_1       |   at org.hibernate.boot.internal.InFlightMetadataCollectorImpl.processEndOfQueue(InFlightMetadataCollectorImpl.java:1752)
web_1       |   at org.hibernate.boot.internal.InFlightMetadataCollectorImpl.processFkSecondPassesInOrder(InFlightMetadataCollectorImpl.java:1696)
web_1       |   at org.hibernate.boot.internal.InFlightMetadataCollectorImpl.processSecondPasses(InFlightMetadataCollectorImpl.java:1583)
web_1       |   at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:278)
web_1       |   at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.build(MetadataBuildingProcess.java:83)
web_1       |   at org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:418)
web_1       |   at org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:87)
web_1       |   at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:692)
web_1       |   at io.dropwizard.hibernate.SessionFactoryFactory.buildSessionFactory(SessionFactoryFactory.java:96)
web_1       |   at io.dropwizard.hibernate.SessionFactoryFactory.build(SessionFactoryFactory.java:49)
web_1       |   at io.dropwizard.hibernate.SessionFactoryFactory.build(SessionFactoryFactory.java:39)
web_1       |   at io.dropwizard.hibernate.HibernateBundle.run(HibernateBundle.java:62)
web_1       |   at io.dropwizard.hibernate.HibernateBundle.run(HibernateBundle.java:15)
web_1       |   at io.dropwizard.setup.Bootstrap.run(Bootstrap.java:200)
web_1       |   at io.dropwizard.cli.EnvironmentCommand.run(EnvironmentCommand.java:42)
web_1       |   at io.dropwizard.cli.ConfiguredCommand.run(ConfiguredCommand.java:85)
web_1       |   at io.dropwizard.cli.Cli.run(Cli.java:75)
web_1       |   at io.dropwizard.Application.run(Application.java:79)
web_1       |   at EdgeApplication.main(EdgeApplication.java:103)

Resource class:

@Data
@Entity
@Table(name="EDGE_RESOURCE")
public class Resource {
    ...

    @ManyToOne
    private List<Coordinate> coordinates;

    ...
}

Referenced Coordinate class

@Data
@Entity
@Table(name="EDGE_COORDINATE")
public class Coordinate {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private long id;

    private double
                latitude,
                longitude;
}

It's dropwizard, with dropwizard-guice.

public class EdgeApplication extends Application<EdgeConfiguration> {

    public static final HibernateBundle<EdgeConfiguration> hibernate = new HibernateBundle<EdgeConfiguration>(Coordinate.class, Session.class, Resource.class) {
        @Override
        public DataSourceFactory getDataSourceFactory(EdgeConfiguration configuration) {
            return configuration.getDatabase();
        }
    };

    @Override
    public void initialize(final Bootstrap<EdgeConfiguration> bootstrap) {
        bootstrap.addBundle(hibernate);

        ...
    }

    ...

}

Upvotes: 5

Views: 8063

Answers (2)

Pavlo
Pavlo

Reputation: 21

in my case it was typo - @OneToOne instead @OneToMany

Upvotes: 1

Saroj Kumar Vaishya
Saroj Kumar Vaishya

Reputation: 31

use @ManyToOne(targetEntity = Entity.class)

Upvotes: 3

Related Questions