组件映射

User.java
package cn.lxl.pojo;

import java.io.Serializable;

public class User implements Serializable {

	private static final long serialVersionUID = 1L;
	private int id;
	private String username;
	private String password;
	private Profile profile;

	public User() {
	}

	public Profile getProfile() {
		return profile;
	}

	public void setProfile(Profile profile) {
		this.profile = profile;
	}

	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;
	}
}

 

Profile.java
package cn.lxl.pojo;

import java.io.Serializable;

public class Profile implements Serializable {

	private static final long serialVersionUID = 1L;
	private String email;
	private String address;
	private String postcode;
	private String mobile;
	private User user;

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	public Profile() {
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getAddress() {
		return address;
	}

	public void setAddress(String address) {
		this.address = address;
	}

	public String getPostcode() {
		return postcode;
	}

	public void setPostcode(String postcode) {
		this.postcode = postcode;
	}

	public String getMobile() {
		return mobile;
	}

	public void setMobile(String mobile) {
		this.mobile = mobile;
	}

	public String getPhone() {
		return phone;
	}

	public void setPhone(String phone) {
		this.phone = phone;
	}

	private String phone;
}

 

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>
	<class name="cn.lxl.pojo.User" table="USERS" schema="SCOTT">
		<id name="id" type="java.lang.Integer">
			<column name="ID" precision="22" scale="0" />
			<generator class="increment">
				<!--  <param name="sequence">gb_seq</param>-->
			</generator>
		</id>
		<property name="username" type="java.lang.String">
			<column name="USERNAME" length="20" />
		</property>
		<property name="password" type="java.lang.String">
			<column name="PASSWORD" length="20" />
		</property>
		<!-- component 组件映射 在User.hbm.xml中映射Profile中的属性 -->
		<component name="profile" class="cn.lxl.pojo.Profile">
		<parent name="user"></parent>
			<property name="email" type="java.lang.String">
				<column name="EMAIL" length="20" />
			</property>
			<property name="address" type="java.lang.String">
				<column name="ADDRESS" length="20" />
			</property>
			<property name="postcode" type="java.lang.String">
				<column name="POSTCODE" length="20" />
			</property>
			<property name="mobile" type="java.lang.String">
				<column name="MOBILE" length="20" />
			</property>
			<property name="phone" type="java.lang.String">
				<column name="PHONE" length="20" />
			</property>
		</component>
	</class>
</hibernate-mapping>

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值