具体的类映射成一张表

User.java
package cn.lxl.pojo;

public abstract class Users {
	private int id;
	private String username;
	private String password;
	public int getId() {
		return id;
	}
	public void setId(int 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;
	}
}

 

Guest.java
package cn.lxl.pojo;

public class Guest extends Users {
	private String loginTime;

	public String getLoginTime() {
		return loginTime;
	}

	public void setLoginTime(String loginTime) {
		this.loginTime = loginTime;
	}
}

 

Admin.java
package cn.lxl.pojo;

public class Admin extends Users {
	private String manSuc;

	public String getManSuc() {
		return manSuc;
	}

	public void setManSuc(String manSuc) {
		this.manSuc = manSuc;
	}
}

 

 

Users.hbm.xml
<?xml version="1.0"?>
<!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.lxl.pojo.Users" abstract="true">
		<id name="id">
			<generator class="increment"/>
		</id>
		<property name="username" type="java.lang.String">
			<column name="username"/>
		</property>
		<property name="password" type="java.lang.String">
			<column name="password"/>
		</property>
		<union-subclass name="cn.lxl.pojo.Admin" table="users_admin">
			<property name="manSuc" type="java.lang.String">
				<column name="man_suc"/>
			</property>
		</union-subclass>
		<union-subclass name="cn.lxl.pojo.Guest" table="users_guest">
			<property name="loginTime" type="java.lang.String">
				<column name="login_time"/>
			</property>
		</union-subclass>
	</class>
</hibernate-mapping>

  

你可能感兴趣的:(java,Hibernate,xml,.net)