首页 新闻 会员 周边 捐助

用hibernate,明明配置文件路劲正确,可是一直报错!求大神解救

0
[已解决问题] 解决于 2016-10-19 14:31

这是我的文件结构

<hibernate-mapping>
<class name="com.imooc.entity.Grade" table="grade">
<id name="gid" column="gid" type="java.lang.Integer">
<generator class="increment"></generator>
</id>
<property name="gname" type="java.lang.String">
<column name="gname" length="20" not-null="true"></column>
</property>
<property name="gdesc">
<column name="gdesc"></column>
</property>
<!-- 配置一对多关联关系 -->
<set name="students" table="student">
<key column="gid"></key>
<one-to-many class="com.wzl.entity.Student"/>
</set>
</class>
</hibernate-mapping>
hibernate.cfg.xml
<hibernate-configuration>
    <session-factory>
        <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
        <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
        <property name="hibernate.connection.username">root</property>
        <property name="hibernate.connection.password">123</property>
        <property name="hibernate.connection.url">
        <![CDATA[
        jdbc:mysql://localhost:3306/wzl?useUnicode=true&characterEncoding=utf8
        ]]>
        </property>
        <property name="show_sql">true</property>
        <property name="hbm2ddl.auto">update</property>
    
    <!-- 指定映射文件的路径 -->
    <mapping resource="com.wzl.entity.Grade.hbm.xml"/>
    <mapping resource="com.wzl.entity.Student.hbm.xml"/>
    </session-factory>
</hibernate-configuration>

报错:

十月 08, 2016 12:51:42 下午 org.hibernate.annotations.common.Version <clinit>

INFO: HCANN000001: Hibernate Commons Annotations {4.0.2.Final}

十月 08, 2016 12:51:42 下午 org.hibernate.Version logVersion

INFO: HHH000412: Hibernate Core {4.2.4.Final}

十月 08, 2016 12:51:42 下午 org.hibernate.cfg.Environment <clinit>

INFO: HHH000206: hibernate.properties not found

十月 08, 2016 12:51:42 下午 org.hibernate.cfg.Environment buildBytecodeProvider

INFO: HHH000021: Bytecode provider name : javassist

十月 08, 2016 12:51:42 下午 org.hibernate.cfg.Configuration configure

INFO: HHH000043: Configuring from resource: /hibernate.cfg.xml

十月 08, 2016 12:51:42 下午 org.hibernate.cfg.Configuration getConfigurationInputStream

INFO: HHH000040: Configuration resource: /hibernate.cfg.xml

十月 08, 2016 12:51:42 下午 org.hibernate.cfg.Configuration addResource

INFO: HHH000221: Reading mappings from resource: com.wzl.entity.Grade.hbm.xml

Exception in thread "main" org.hibernate.MappingNotFoundException: resource: com.wzl.entity.Grade.hbm.xml not found

at org.hibernate.cfg.Configuration.addResource(Configuration.java:738)

at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:2188)

at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:2160)

at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2140)

at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2093)

at org.hibernate.cfg.Configuration.configure(Configuration.java:2008)

at org.hibernate.cfg.Configuration.configure(Configuration.java:1987)

at com.wzl.test.Test2.add(Test2.java:34)

at com.wzl.test.Test2.main(Test2.java:20)

求大神解答

努力小码的主页 努力小码 | 初学一级 | 园豆:146
提问于:2016-10-08 13:21
< >
分享
最佳答案
1

Grade.hbm.xml配置文件中的<class name="com.imooc.entity.Grade" table="grade">应该为<class name="com.wzl.entity.Grade" table="grade">

奖励园豆:5
寒塘渡鹤影冷月葬花魂 | 菜鸟二级 |园豆:211 | 2016-10-08 18:04
其他回答(2)
0

Exception in thread "main" org.hibernate.MappingNotFoundException: resource: com.wzl.entity.Grade.hbm.xml not found

上边的文件配置有问题

 

jgig11 | 园豆:338 (菜鸟二级) | 2016-10-11 09:35
0

 映射文件资源路径配置的问题,可以参考楼上回复

DREAM_SF | 园豆:206 (菜鸟二级) | 2016-10-13 09:41
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册