hibernate多对一双向关联

阅读更多

一、创建实体类

package com.wr.hibernate.entity;

import java.util.HashSet;
import java.util.Set;

public class Custom {

	private int customId;
	private String customName;
	private Set orders = new HashSet();

	public Set getOrders() {
		return orders;
	}

	public void setOrders(Set orders) {
		this.orders = orders;
	}

	public int getCustomId() {
		return customId;
	}

	public void setCustomId(int customId) {
		this.customId = customId;
	}

	public String getCustomName() {
		return customName;
	}

	public void setCustomName(String customName) {
		this.customName = customName;
	}

	public Custom(int customId, String customName) {
		super();
		this.customId = customId;
		this.customName = customName;
	}

	public Custom() {
		super();
		// TODO Auto-generated constructor stub
	}

	@Override
	public String toString() {
		return "Custom [customId=" + customId + ", customName=" + customName + "]";
	}

}

 

package com.wr.hibernate.entity;

public class Order {

	private int orderId;
	private String orderName;
	private Custom custom;

	public Custom getCustom() {
		return custom;
	}

	public void setCustom(Custom custom) {
		this.custom = custom;
	}

	public int getOrderId() {
		return orderId;
	}

	public void setOrderId(int orderId) {
		this.orderId = orderId;
	}

	public String getOrderName() {
		return orderName;
	}

	public void setOrderName(String orderName) {
		this.orderName = orderName;
	}

	@Override
	public String toString() {
		return "Order [orderId=" + orderId + ", orderName=" + orderName + ", custom=" + custom + "]";
	}

}

 

二、POJO配置文件

 






	

		
			
			
			
		

		
			
		
		
		
		
			
			
		

	


 

package com.wr.hibernate.entity;

public class Order {

	private int orderId;
	private String orderName;
	private Custom custom;

	public Custom getCustom() {
		return custom;
	}

	public void setCustom(Custom custom) {
		this.custom = custom;
	}

	public int getOrderId() {
		return orderId;
	}

	public void setOrderId(int orderId) {
		this.orderId = orderId;
	}

	public String getOrderName() {
		return orderName;
	}

	public void setOrderName(String orderName) {
		this.orderName = orderName;
	}

	@Override
	public String toString() {
		return "Order [orderId=" + orderId + ", orderName=" + orderName + ", custom=" + custom + "]";
	}

}

 

你可能感兴趣的:(hibernate,java,orm)