Use hibernate entities from external jar

2019-07-31 13:46发布

问题:

I have created jhipster microservice application, in which i have added a "demographics.jar" file as a dependency.

demographics.jar file contains a class "Address.java" which is JPA entity.

when i refer this class from my code, it generated following error

org.hibernate.AnnotationException: @OneToOne or @ManyToOne on com.example.jobcard.domain.JobCard.location references an unknown entity: com.example.geographics.domain.Address
    at org.hibernate.cfg.ToOneFkSecondPass.doSecondPass(ToOneFkSecondPass.java:109)
    at org.hibernate.cfg.Configuration.processEndOfQueue(Configuration.java:1598)
    at org.hibernate.cfg.Configuration.processFkSecondPassInOrder(Configuration.java:1521)
    at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1422)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1846)
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:857)
    ... 28 common frames omitted

jhipster version is : 3.6.1

jdk verison is : 1.8.0_91

here is the parent pom details :

<parent>
        <artifactId>spring-boot-starter-parent</artifactId>
        <groupId>org.springframework.boot</groupId>
        <version>1.4.0.RELEASE</version>
        <relativePath/>
    </parent>

I have ready many solutions which suggest to edit the persistence.xml file, but persistence.xml file is not generated by jhipster.

回答1:

Your @EntityScan annotation is probably wrong to scan your 2 packages: com.example.jobcard.domain and com.example.geographics.domain