简体   繁体   中英

JPA: Unable to resolve explicitly named mapping-file in JavaSE

I am making a small program to migrate data from another system we don't own, to a custom one we are making inside our company. I am using IntellJ with Maven, but the error seems to come from the target folder after building as It seems unable to find the folder, and when I browse inside it, Intellij gives me an error.

persistence.xml in src/ I cut a bit so I don't bloat this post with a big image. src /中的Persistence.xml

Here is a small screenshot of the output after doing compiling as you can see the files are placed where they belong.

编译后输出

And when I check the persistence.xml inside the folder, here Intellij says that the files cannot be resolved.

目标文件夹persistence.xml

This is not the original location of those xml files, as they were generated by the IDE inside the package edu.apde.f5.model.$project, at first they were not included in the build so I moved them inside the resources/META-INF/etc path, and they appeared, but It is still giving the same error. Also tried with the path META-INF/$project-mapping and still nothing.

Error received in output, this is the error I get after trying to run the project, this occurs when I call Entity Manager and I call the "MsSchoolPersistenceUnit"

java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:297)
at java.lang.Thread.run(Thread.java:748)
Caused by: org.hibernate.boot.MappingException: Unable to resolve explicitly named mapping-file : src/main/resources/META-INF/msschool-mapping/ScReligion.xml : origin(src/main/resources/META-INF/msschool-mapping/ScReligion.xml)
at org.hibernate.boot.model.process.internal.ScanningCoordinator.applyScanResultsToManagedResources(ScanningCoordinator.java:214)
at org.hibernate.boot.model.process.internal.ScanningCoordinator.coordinateScan(ScanningCoordinator.java:82)
at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.prepare(MetadataBuildingProcess.java:99)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.<init>(EntityManagerFactoryBuilderImpl.java:232)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.<init>(EntityManagerFactoryBuilderImpl.java:174)
at org.hibernate.jpa.boot.spi.Bootstrap.getEntityManagerFactoryBuilder(Bootstrap.java:76)
at org.hibernate.jpa.HibernatePersistenceProvider.getEntityManagerFactoryBuilder(HibernatePersistenceProvider.java:171)
at org.hibernate.jpa.HibernatePersistenceProvider.getEntityManagerFactoryBuilderOrNull(HibernatePersistenceProvider.java:119)
at org.hibernate.jpa.HibernatePersistenceProvider.getEntityManagerFactoryBuilderOrNull(HibernatePersistenceProvider.java:61)
at org.hibernate.jpa.HibernatePersistenceProvider.createEntityManagerFactory(HibernatePersistenceProvider.java:50)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:79)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:54)
at edu.apde.f5.util.EntityManagerUtil.getEntityManager(EntityManagerUtil.java:12)
at edu.apde.f5.data.msschool.AlumnoRepository.fetchAll(AlumnoRepository.java:17)
at edu.apde.f5.main.Main.main(Main.java:10)
... 6 more
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE

The Classpath needs to point to the containing folder of src/main/resources/META-INF/msschool-mapping/ScReligion.xml.

Another option is to modify the mapping file entry to point to the file relative to the existing Classpath.

Another option is to give it an absolute path to the file.

尝试将映射文件指向META-INF / msschool-mapping / ScFamiglia.xml Es。

<mapping-file>META-INF/msschool-mapping/yourorms*.xml</mapping-file>

我通过在每个<mapping-file></mapping-file>标记中的src之前添加一个前导“ /”来解决该问题。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM