自关联的表怎么优化查询速度!

宇宙最强皮皮虾 2016-07-08 03:40:58


@Entity
@Table(name = "BMS_Rights")
public class RightsBean extends IdEntity implements Serializable {

private static final long serialVersionUID = 1L;

private String parentId; //父ID

private String name; //模块名称

private String path; //路径

private String remark; //描述

private String direction; //菜单方向

private String iconCls; //菜单图标样式class

private int isButton; //菜单是否为按钮级别,0否,1是

//角色
private List<RoleBean> role = Lists.newArrayList();

//表示资源下所属的功能(资源)
private List<RightsBean> childRights = Lists.newArrayList();

@Column(name="ParentID",length=32)
public String getParentId() {
return parentId;
}

public void setParentId(String parentId) {
this.parentId = parentId;
}

@Column(name="Name")
public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

@Column(name="Path")
public String getPath() {
return path;
}

public void setPath(String path) {
this.path = path;
}

@ManyToMany(fetch = FetchType.LAZY, mappedBy = "rights")
public List<RoleBean> getRole() {
return role;
}

public void setRole(List<RoleBean> role) {
this.role = role;
}

@Column(name="Remark")
public String getRemark() {
return remark;
}

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

@Column(name="Direction")
public String getDirection() {
return direction;
}

public void setDirection(String direction) {
this.direction = direction;
}

/**
* 不查询按钮级别的子菜单
*/
@OneToMany(fetch = FetchType.EAGER, mappedBy="parentId")
@Where(clause = "IsButton=0")
public List<RightsBean> getChildRights() {
return childRights;
}

public void setChildRights(List<RightsBean> childRights) {
this.childRights = childRights;
}

@Column(name="IconCls")
public String getIconCls() {
return iconCls;
}

public void setIconCls(String iconCls) {
this.iconCls = iconCls;
}

@Column(name="IsButton")
public int getIsButton() {
return isButton;
}

public void setIsButton(int isButton) {
this.isButton = isButton;
}

}



查询这个表的时候会输出很多行SQL语句,后来发现是因为childRights这个属性。

如果去掉急加载速度就变快了,可是后台需要改的东西太多,请问在不去除急加载的情况下怎么优化?
...全文
128 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复


package com.cicro.bms.entity.rights;

import java.io.Serializable;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.Table;
import javax.persistence.Transient;

import com.cicro.bms.entity.role.RoleBean;
import com.google.common.collect.Lists;

/**
 * 权限
 */
@Entity
@Table(name = "BMS_Rights")
public class RightsBean implements Serializable {
	
	private static final long serialVersionUID = 1L;
	
	private Integer id;		//编号
	
	private Integer parentId;		//父ID
	
	private String name;		//模块名称
	
	private String path;		//路径
	
	private String remark;		//描述
	
	private String direction;		//菜单方向
	
	private String iconCls;		//菜单图标样式class
	
	private Integer isButton;		//菜单是否为按钮级别,0否,1是
	
	private Integer isSystem;		//是否为系统默认权限:0不是  1是
	
	//角色
	private List<RoleBean> role = Lists.newArrayList();
	
	//表示资源下所属的功能(资源)
	private List<RightsBean> childRights = Lists.newArrayList();

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@Column(name = "ID", nullable = false)
	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	@Column(name="ParentID")
	public Integer getParentId() {
		return parentId;
	}

	public void setParentId(Integer parentId) {
		this.parentId = parentId;
	}

	@Column(name="Name")
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@Column(name="Path")
	public String getPath() {
		return path;
	}

	public void setPath(String path) {
		this.path = path;
	}

	@ManyToMany(fetch = FetchType.LAZY, mappedBy = "rights")
	public List<RoleBean> getRole() {
		return role;
	}

	public void setRole(List<RoleBean> role) {
		this.role = role;
	}

	@Column(name="Remark")
	public String getRemark() {
		return remark;
	}

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

	@Column(name="Direction")
	public String getDirection() {
		return direction;
	}

	public void setDirection(String direction) {
		this.direction = direction;
	}

	@Column(name="IconCls")
	public String getIconCls() {
		return iconCls;
	}

	public void setIconCls(String iconCls) {
		this.iconCls = iconCls;
	}

	@Column(name="IsButton")
	public Integer getIsButton() {
		return isButton;
	}

	public void setIsButton(Integer isButton) {
		this.isButton = isButton;
	}

	@Column(name="IsSystem")
	public Integer getIsSystem() {
		return isSystem;
	}

	public void setIsSystem(Integer isSystem) {
		this.isSystem = isSystem;
	}
	
	@Transient
	public List<RightsBean> getChildRights() {
		return childRights;
	}

	public void setChildRights(List<RightsBean> childRights) {
		this.childRights = childRights;
	}
	
}

67,512

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧