首页 > 代码库 > hibernate注解实现set集合排序

hibernate注解实现set集合排序

package com.dc.product.entity.res;

// Generated 2014-11-28 16:53:22 by Hibernate Tools 3.4.0.CR1

import java.math.BigDecimal;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import org.hibernate.validator.Length;
import org.hibernate.validator.NotNull;

/**
 * ResourceGroupDef generated by hbm2java
 */
@Entity
@Table(name = "T_RES_RESOURCEGROUPDEF", schema = "PROD")
public class ResourceGroupDef implements java.io.Serializable {

	private String resourceGroup;
	private ResourceGroupDef resourceGroupDef;
	private ResourceClass resourceClass;
	private String groupName;
	private String groupAttr;
	private BigDecimal groupLevel;
	private BigDecimal displayOrder;
	private String modifyStaff;
	private Date modifyDate;
	private String remark;
	private Set<ResourceGroupDef> resourceGroupDefs = new HashSet<ResourceGroupDef>(
			0);
	private Set<ResourceBaseInfo> resourceBaseInfos = new HashSet<ResourceBaseInfo>(
			0);

	public ResourceGroupDef() {
	}

	public ResourceGroupDef(String resourceGroup, String groupName,
			String groupAttr, BigDecimal groupLevel, BigDecimal displayOrder) {
		this.resourceGroup = resourceGroup;
		this.groupName = groupName;
		this.groupAttr = groupAttr;
		this.groupLevel = groupLevel;
		this.displayOrder = displayOrder;
	}

	public ResourceGroupDef(String resourceGroup,
			ResourceGroupDef resourceGroupDef, ResourceClass resourceClass,
			String groupName, String groupAttr, BigDecimal groupLevel,
			BigDecimal displayOrder, String modifyStaff, Date modifyDate,
			String remark, Set<ResourceGroupDef> resourceGroupDefs,
			Set<ResourceBaseInfo> resourceBaseInfos) {
		this.resourceGroup = resourceGroup;
		this.resourceGroupDef = resourceGroupDef;
		this.resourceClass = resourceClass;
		this.groupName = groupName;
		this.groupAttr = groupAttr;
		this.groupLevel = groupLevel;
		this.displayOrder = displayOrder;
		this.modifyStaff = modifyStaff;
		this.modifyDate = modifyDate;
		this.remark = remark;
		this.resourceGroupDefs = resourceGroupDefs;
		this.resourceBaseInfos = resourceBaseInfos;
	}

	@Id
	@Column(name = "RESOURCE_GROUP", unique = true, nullable = false, length = 15)
	@NotNull
	@Length(max = 15)
	public String getResourceGroup() {
		return this.resourceGroup;
	}

	public void setResourceGroup(String resourceGroup) {
		this.resourceGroup = resourceGroup;
	}

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "UP_RESOURCE_GROUP")
	public ResourceGroupDef getResourceGroupDef() {
		return this.resourceGroupDef;
	}

	public void setResourceGroupDef(ResourceGroupDef resourceGroupDef) {
		this.resourceGroupDef = resourceGroupDef;
	}

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "RESOURCE_CLASS")
	public ResourceClass getResourceClass() {
		return this.resourceClass;
	}

	public void setResourceClass(ResourceClass resourceClass) {
		this.resourceClass = resourceClass;
	}

	@Column(name = "GROUP_NAME", nullable = false, length = 128)
	@NotNull
	@Length(max = 128)
	public String getGroupName() {
		return this.groupName;
	}

	public void setGroupName(String groupName) {
		this.groupName = groupName;
	}

	@Column(name = "GROUP_ATTR", length = 2)
	@NotNull
	@Length(max = 2)
	public String getGroupAttr() {
		return this.groupAttr;
	}

	public void setGroupAttr(String groupAttr) {
		this.groupAttr = groupAttr;
	}

	@Column(name = "GROUP_LEVEL", nullable = false, precision = 22, scale = 0)
	@NotNull
	public BigDecimal getGroupLevel() {
		return this.groupLevel;
	}

	public void setGroupLevel(BigDecimal groupLevel) {
		this.groupLevel = groupLevel;
	}

	@Column(name = "DISPLAY_ORDER", nullable = false, precision = 22, scale = 0)
	@NotNull
	public BigDecimal getDisplayOrder() {
		return this.displayOrder;
	}

	public void setDisplayOrder(BigDecimal displayOrder) {
		this.displayOrder = displayOrder;
	}

	@Column(name = "MODIFY_STAFF", length = 15)
	@Length(max = 15)
	public String getModifyStaff() {
		return this.modifyStaff;
	}

	public void setModifyStaff(String modifyStaff) {
		this.modifyStaff = modifyStaff;
	}

	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "MODIFY_DATE", length = 7)
	public Date getModifyDate() {
		return this.modifyDate;
	}

	public void setModifyDate(Date modifyDate) {
		this.modifyDate = modifyDate;
	}

	@Column(name = "REMARK", length = 128)
	@Length(max = 128)
	public String getRemark() {
		return this.remark;
	}

	public void setRemark(String remark) {
		this.remark = remark;
	}

	@OneToMany(fetch = FetchType.LAZY, mappedBy = "resourceGroupDef")
	@OrderBy("displayOrder")
	public Set<ResourceGroupDef> getResourceGroupDefs() {
		return this.resourceGroupDefs;
	}

	public void setResourceGroupDefs(Set<ResourceGroupDef> resourceGroupDefs) {
		this.resourceGroupDefs = resourceGroupDefs;
	}

	@OneToMany(fetch = FetchType.LAZY, mappedBy = "resourceGroupDef")
	public Set<ResourceBaseInfo> getResourceBaseInfos() {
		return this.resourceBaseInfos;
	}

	public void setResourceBaseInfos(Set<ResourceBaseInfo> resourceBaseInfos) {
		this.resourceBaseInfos = resourceBaseInfos;
	}

}

核心的部分:

@OneToMany(fetch = FetchType.LAZY, mappedBy = "resourceGroupDef")
	@OrderBy("displayOrder")
	public Set<ResourceGroupDef> getResourceGroupDefs() {
		return this.resourceGroupDefs;
	}



hibernate注解实现set集合排序