eclipse2.1下使用hibernate,按照如下步骤碰到问题:
Error reading resource: com/mycomply/Owner.hbm ?
1.WEB-INF/src下新建hibernate.cfg.xml文件
文件内容: .......
<mapping resource="com/mycomply/Owner.hbm" /> 这个有没有问题
2.WEB-INF/com/mycomply下新建映射文件Owner.hbm
对应的数据表owner中有两个字段:
id: int,主键
name:char
文件内容
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >
<hibernate-mapping>
<class name="com.mycomply.Owner" table="owner">
<id
name="id"
type="int"
column="id"
>
<generator class="assigned"/>
</id>
<property
name="name"
column="name"
type="String"
not-null="true"
/>
</class>
</hibernate-mapping>
3.用下面代码测试:
SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
Session s = sessionFactory.openSession();
Owner owner=new Owner();
owner.setId(id);
owner.setName(name);
s.save(owner);
报错:
Error reading resource: com/mycomply/Owner.hbm
------解决方法--------------------------------------------------------
com/mycomply/Owner.hbm
那这个文件,到底有没有呀,
------解决方法--------------------------------------------------------
Owner.hbm.xml试试
------解决方法--------------------------------------------------------
应该是数据库里面没有定义主键,定义主键后重新生成hbm文件就没有问题了,你可以参考!