hibernate学习之1:m映射

Account.java:
package domain;

public class Account {
	private String id;
	private String acctNo;
	private double bal;
	private User owner;
	public Account(){}
	public Account(String acctNo,double bal){
		this.acctNo=acctNo;
		this.bal=bal;
	}
	public String getId() {
		return id;
	}
	public void setId(String id) {
		this.id = id;
	}
	public String getAcctNo() {
		return acctNo;
	}
	public void setAcctNo(String acctNo) {
		this.acctNo = acctNo;
	}
	public double getBal() {
		return bal;
	}
	public void setBal(double bal) {
		this.bal = bal;
	}
	public User getOwner() {
		return owner;
	}
	public void setOwner(User owner) {
		this.owner = owner;
	}
	
}

User.java:
package domain;

import java.util.Set;

public class User {
	private String id;
	private String name;
	private int age;
	private Set<Account> accts;
	public User(){}
	public User(String name,int age){
		this.name=name;
		this.age=age;
	}
	public String getId() {
		return id;
	}
	public void setId(String id) {
		this.id = id;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public int getAge() {
		return age;
	}
	public void setAge(int age) {
		this.age = age;
	}
	public Set<Account> getAccts() {
		return accts;
	}
	public void setAccts(Set<Account> accts) {
		this.accts = accts;
	}
	
}

Account.hbm.xml:
<?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="domain.Account" table="ACCOUNT">
		<id name="id" column="id">
			<generator class="uuid"></generator>
		</id>
		<property name="acctNo" column="ACCTNO"></property>
		<property name="bal" column="BAL"></property>
		<many-to-one name="owner" column="FID"></many-to-one>
	</class>
</hibernate-mapping>

User.hbm.xml:
<?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 package="domain">
	<class name="User" table="USERS">
		<id name="id" column="id">
			<generator class="uuid"></generator>
		</id>
		<property name="name"></property>
		<property name="age" column="AGE"></property>
		<set name="accts" inverse="true" cascade="all">
			<key column="FID"></key>
			<one-to-many class="Account" />
		</set>
	</class>
</hibernate-mapping>

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