使用hibernate出错了请帮我看看

05-03-23 zhangbo198294

运行测试程序的时候抛出了Error reading resource: userInfo/User.hbm.xml的异常:

请帮我看看这个User.hbm.xml里哪写的不对谢谢!

<?xml version="1.0" encoding="utf-8"?> 
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN" "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd"> 
<hibernate-mapping> 
<class name="userInfo.User" table="usersinfo"> 

<id name="userName" type="String" unsaved-value="null" >
<column name="username" sql-type="varchar(30)" not-null="true" />
<generator class="Assigned"/>
</id>	
<property name="age" type="int"> 
<column name="age" sql-type="int" not-null="true"/> 
</property> 

<property name="address" type="string"> 
<column name="address" sql-type="varchar(60)" /> 
</property> 

</class> 
</hibernate-mapping> 
对应的JAVA类: 
package userInfo; 

import java.io.Serializable; 

public class User implements Serializable{ 

private String userName; 
private int age; 
private String address; 



/** 
* @return Returns the address. 
*/ 
public String getAddress() { 
return address; 
} 
/** 
* @param address The address to set. 
*/ 
public void setAddress(String address) { 
this.address = address; 
} 
/** 
* @return Returns the age. 
*/ 
public int getAge() { 
return age; 
} 
/** 
* @param age The age to set. 
*/ 
public void setAge(int age) { 
this.age = age; 
} 
/** 
* @return Returns the name. 
*/ 
public String getUserName() { 
return userName; 
} 
/** 
* @param name The name to set. 
*/ 
public void setUserName(String userName) { 
this.userName = userName; 
} 
}

<p>

SportsBaby1980
2005-03-23 23:30

有id字段吗?

SportsBaby1980
2005-03-24 21:43

我竟然以为你是用xdoclet写的

不好意思

你的这些字段都很简单

你可以参考 hibernate的例子,好像在hibernate的eg目录下

注意一般要有id字段