报错信息:
Initial SessionFactory creation failed.org.hibernate.InvalidMappingException: Could not parse mapping document from resource cn/jbit/pojo/User.hbm.xml
user实体类
public class User {
private Integer id;
private String username;
private String password;
private Date birthday;
private Integer age;
private Address address;
public Address getAddress() {
return address;
}
public void setAddress(Address address) {
this.address = address;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public Date getBirthday() {
return birthday;
}
public void setBirthday(Date birthday) {
this.birthday = birthday;
}
public Integer getAge() {
return age;
}
public void setAge(Integer age) {
this.age = age;
}
}
Address实体类
package cn.jbit.pojo;
public class Address {
private User user;
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
private Integer id;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
private String country;
private String city;
public String getCountry() {
return country;
}
public void setCountry(String country) {
this.country = country;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
}
user映射文件
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="cn.jbit.pojo.User" table="userinfo" >
<id name="id" type="java.lang.Integer" >
<column name="id"></column>
<generator class="sequence">
<param name="sequence">seq1</param>
</generator>
</id>
<property name="userName"></property>
<property name="password"></property>
<property name="birthday" type="java.util.Date"></property>
<property name="age" type="java.lang.Integer"></property>
<one-to-one name="address" class="cn.jbit.pojo.Address" property-ref="user">
</one-to-one>
</class>
</hibernate-mapping>
Address映射文件
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="cn.jbit.pojo.Address" table="Address" >
<id name="id" type="java.lang.Integer" >
<generator class="assigned">
</generator>
</id>
<property name="country"></property>
<property name="city"></property>
<many-to-one name="user" class="cn.jbit.pojo.User" unique="true">
<column name="userid"></column>
</many-to-one>
</class>
</hibernate-mapping>
配置文件
<?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="hibernate.connection.url">
jdbc:oracle:thin:@localhost:1521:ZXC
</property>
<property name="hibernate.connection.username">test</property>
<property name="hibernate.connection.password">test</property>
<property name="hibernate.connection.driver_class">