引用一个未知实体:java.util.List

时间:2016-12-12 15:37:36

标签: java hibernate jpa dropwizard

有谁能建议我在这里缺少什么?启动dropwizard应用程序时出错。

错误:

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)

资源类:

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

    @ManyToOne
    private List<Coordinate> coordinates;

    ...
}

参考坐标类

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

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

    private double
                latitude,
                longitude;
}

这是一个投掷蜥蜴,带着霰弹枪。

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);

        ...
    }

    ...

}

0 个答案:

没有答案