未找到hibernate映射资源

时间:2016-04-16 01:44:09

标签: java hibernate

我有一个MappingNotFoundException:资源:找不到TradFileRecord.hbm.xml

这是在核心配置中

像hibernate.cfg.xml文件这样的文件位于src / main / resources

hibernate文件的内容

     <?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-configuration SYSTEM 
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
   <session-factory>
   <property name="hibernate.dialect">
      org.hibernate.dialect.PostgreSQLDialect
   </property>
   <property name="hibernate.connection.driver_class">
      org.postgresql.Driver
   </property>
   <property name="hibernate.connection.url">
      jdbc:postgresql://localhost:5432/Subtitlor
   </property>
   <property name="hibernate.connection.username">
      postgres
   </property>
   <property name="hibernate.connection.password">
      1234
   </property>

    <property name="show_sql">true</property>

      <!-- mapping files -->
        <mapping resource="TradFileRecord.hbm.xml"/>

        <!-- cache settings -->
        <class-cache class="com.subtitlor.bean.TradFileRecord" usage="read-write"/>


<!-- <mapping resource="src/main/resources/TradFileRecord.hbm.xml"/> -->
<!-- <mapping class="com/subtitlor/bean/TradFileRecord"/> -->
</session-factory>
</hibernate-configuration>

和映射文件的内容

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

<hibernate-mapping>
   <class name="com.subtitlor.bean.TradFileRecord" table="tradfilerecord">
      <meta attribute="class-description">
         This class contains the TradFileRecord detail. 
      </meta>
      <id name="idLigne" type="int" column="idline">
         <generator class="native"/>
      </id>
      <property name="timeValues" column="timevalues" type="string"/>
      <property name="originalLine1" column="text1" type="string"/>
      <property name="originalLine2" column="text2" type="int"/>
      <property name="TranslatedLine1" column="translatedtext1" type="string"/>
      <property name="TranslatedLine2" column="translatedtext2" type="string"/>
      <property name="fileName" column="filename" type="string"/>
      <property name="descriptionFile" column="descriptionfile" type="string"/>
   </class>
</hibernate-mapping>

和注释配置我有另一个错误:无法加载注释

请你帮帮我

我忘记了我的pom.xml

<dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>4.0.1.Final</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-validator</artifactId>
            <version>4.0.1.Final</version>
        </dependency>
    <!--    <dependency>
            <groupId>org.hibernate.common</groupId>
            <artifactId>hibernate-commons-annotations</artifactId>
            <version>4.0.1.Final</version>
            <classifier>tests</classifier>
        </dependency> -->
    <!--    <dependency>
            <groupId>hibernate-annotations</groupId>
            <artifactId>hibernate-annotations</artifactId>
            <version>3.3.0.GA</version>
        </dependency> -->
        <!-- <dependency>
            <groupId>hibernate-commons-annotations</groupId>
            <artifactId>hibernate-commons-annotations</artifactId>
            <version>3.0.0.GA</version>
        </dependency> -->
        <dependency>
            <groupId>org.hibernate.javax.persistence</groupId>
            <artifactId>hibernate-jpa-2.0-api</artifactId>
            <version>1.0.1.Final</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-entitymanager</artifactId>
            <version>4.0.1.Final</version>
        </dependency>
        <dependency>
            <groupId>javax.validation</groupId>
            <artifactId>validation-api</artifactId>
            <version>1.0.0.GA</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
   <groupId>org.hibernate</groupId>
   <artifactId>hibernate-search-orm</artifactId>
   <version>5.5.2.Final</version>
</dependency>

1 个答案:

答案 0 :(得分:0)

你需要确保Maven知道它是一个资源,所以把它放在src / main / resources目录中,然后Maven知道将它复制到位,然后它就是一个资源

除了构建一个源jar之外,Maven将使用src / main / java来构建,但不会将源复制到目标目录,因此它不在已完成的jar中。< / p>

就个人而言,我将映射文件放在与该类相同的包中,因此src / main / resources / com / subtitlor / bean / TradFileRecord.hbm.xml。