org.hibernate.MappingNotFoundException:找不到资源:com / ypd / a / entity / Employee.hbm.xml

时间:2017-03-11 07:34:31

标签: java hibernate junit

我在测试方法时遇到了问题:

  

org.junit.platform.launcher.core.ServiceLoaderTestEngineRegistry loadTestEngines   信息:发现的ID为TestEngines:[junit-jupiter,junit-vintage]   log4j:WARN找不到logger(org.hibernate.type.BasicTypeRegistry)的appender。   log4j:WARN请正确初始化log4j系统。

     

org.hibernate.MappingNotFoundException:resource:com / ypd / a / entity / Employee.hbm.xml not found

     

at org.hibernate.cfg.Configuration.addResource(Configuration.java:769)       在org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:2314)       在org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:2280)       在org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2260)       在org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2213)       在org.hibernate.cfg.Configuration.configure(Configuration.java:2128)       在org.hibernate.cfg.Configuration.configure(Configuration.java:2107)       在com.ypd.a.entity.App.testHello(App.java:24)       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)       在org.junit.platform.commons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:289)       在org.junit.jupiter.engine.execution.ExecutableInvoker.invoke(ExecutableInvoker.java:114)       at org.junit.jupiter.engine.descriptor.MethodTestDescriptor.lambda $ invokeTestMethod $ 7(MethodTestDescriptor.java:212)       在org.junit.jupiter.engine.execution.ThrowableCollector.execute(ThrowableCollector.java:40)       at org.junit.jupiter.engine.descriptor.MethodTestDescriptor.invokeTestMethod(MethodTestDescriptor.java:208)       在org.junit.jupiter.engine.descriptor.MethodTestDescriptor.execute(MethodTestDescriptor.java:155)       at org.junit.jupiter.engine.descriptor.MethodTestDescriptor.execute(MethodTestDescriptor.java:63)       at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.lambda $ execute $ 0(HierarchicalTestExecutor.java:80)       at org.junit.platform.engine.support.hierarchical.SingleTestExecutor.executeSafely(SingleTestExecutor.java:66)       at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:76)       at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.lambda $ execute $ 0(HierarchicalTestExecutor.java:87)       at org.junit.platform.engine.support.hierarchical.SingleTestExecutor.executeSafely(SingleTestExecutor.java:66)       at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:76)       at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.lambda $ execute $ 0(HierarchicalTestExecutor.java:87)       at org.junit.platform.engine.support.hierarchical.SingleTestExecutor.executeSafely(SingleTestExecutor.java:66)       at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:76)       at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:51)       at org.junit.platform.engine.support.hierarchical.HierarchicalTestEngine.execute(HierarchicalTestEngine.java:43)       在org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:129)       在org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:85)       at com.intellij.junit5.JUnit5IdeaTestRunner.startRunnerWithArgs(JUnit5IdeaTestRunner.java:59)       at com.intellij.rt.execution.junit.IdeaTestRunner $ Repeater.startRunnerWithArgs(IdeaTestRunner.java:51)       在com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:237)       在com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)

它声明 org.hibernate.MappingNotFoundException:resource:com / ypd / a / entity / Employee.hbm.xml not found

但是在项目目录中:

Employee.hbm.xml

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
        "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
        "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">



<hibernate-mapping package="com.ypd.a.entity">
    <class name="Employee" table="t_employee">

        <id name="empId" column="id">
            <generator class="native"/>
        </id>

        <property name="empName" column="emp_name"></property>
        <property name="workDate" column="workDate"></property>

    </class>
</hibernate-mapping>

问题出在哪里?

1 个答案:

答案 0 :(得分:1)

您的配置文件应放在资源目录中,java目录只存储.java文件。