hibernate.hbm.xml找不到映射文件

来源:百度知道 编辑:UC知道 时间:2024/05/13 08:35:21
执行数据库操作是抛出异常:%%%% Error Creating SessionFactory %%%%
org.hibernate.MappingException: Resource: /com/cw/x2/auth/common/resac/entity/Stockholder.hbm.xml not found

相关信息:
hibernate.hbm.xml
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
<session-factory>
<property name="connection.driver_class">com.ibm.db2.jcc.DB2Driver</property>
<property name="connection.url">jdbc:db2://localhost:50000/x2</property>
<property name="connection.username">llf</property>

你需要在代码中写
Configuration cfg=new Configuration();
cfg.configure("com/cw/x2/auth/common/resac/entity/Stockholder.hbm.xml");
原因是你改变了Hibernate默认的配置文件的路径和名称,所以你就要明确的指出它的路径和名称,这样Hibernate才能找到它.

有很大可能是那个路径的问题,myEclipse中有hibernate.cfg.xml配置界面吧,从界面中的Add按钮选择路径应该不会错了吧。