PO实现hashCode()方法了没有?实现这个方法能够按方法中的字段排序,你试试。
package net.xsbn.stride.model.realm;
import java.util.Set;
import net.xsbn.stride.model.BaseObject;
import org.apache.commons.lang.builder.CompareToBuilder;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
/**
* 模块(module)实体设计类.
* @author villion
* @hibernate.class table="usr_module"
*/
public class Module extends BaseObject implements Comparable {
/**
* 模块ID, 主键.
*/
private String id;
/**
* 模块名称.
*/
private String moduleName;
/**
* 模块的默认链接.
*/
private String moduleURL;
/**
* 模块图标.
*/
private String moduleIcon;
/**
* 说明.
*/
private String description;
/**
* 模块顺序.
*/
private int moduleOrder;
/**
* 隐藏模块.
* 默认为false,此模块会进行显示.
*/
private boolean hidden;
/**
* 模块非授权.
* 默认为false,必须进行授权管理.
*/
private boolean nonPermit;
/**
* 父模块.
*/
private Module parent;
/**
* 包含操作员.
*/
private Set operators;
/**
* 所属操作组.
*/
private Set groups;
/**
* 所属目录.
*/
private Catalog catalog;
/**
* 帮助文件地址
*/
private String helpUrl;
/**
* Access method for the id property.
*
* @return the current value of the id property
* @hibernate.id generator-class="uuid.hex" not-null="true"
*/
public String getId() {
return id;
}
/**
* Sets the value of the id property.
*
* @param aId the new value of the id property
*/
public void setId(String aId) {
id = aId;
}
/**
* Access method for the moduleName property.
*
* @return the current value of the moduleName property
* @hibernate.property column="modulename"
*/
public String getModuleName() {
return moduleName;
}
/**
* Sets the value of the moduleName property.
*
* @param aModuleName the new value of the moduleName property
*/
public void setModuleName(String aModuleName) {
moduleName = aModuleName;
}
/**
* Access method for the moduleURL property.
*
* @return the current value of the moduleURL property
* @hibernate.property column = "moduleURL"
*/
public String getModuleURL() {
return moduleURL;
}
/**
* Sets the value of the moduleURL property.
*
* @param aModuleURL the new value of the moduleURL property
*/
public void setModuleURL(String aModuleURL) {
moduleURL = aModuleURL;
}
/**
* Access method for the moduleIcon property.
*
* @return the current value of the moduleIcon property
* @hibernate.property column="moduleicon"
*/
public String getModuleIcon() {
return moduleIcon;
}
/**
* Sets the value of the moduleIcon property.
*
* @param aModuleIcon the new value of the moduleIcon property
*/
public void setModuleIcon(String aModuleIcon) {
moduleIcon = aModuleIcon;
}
/**
* Access method for the description property.
*
* @return the current value of the description property
* @hibernate.property
*/
public String getDescription() {
return description;
}
/**
* Sets the value of the description property.
*
* @param aDescription the new value of the description property
*/
public void setDescription(String aDescription) {
this.description = aDescription;
}
/**
* @return Returns the moduleOrder.
* @hibernate.property column="moduleorder" not-null = "true"
*/
public int getModuleOrder() {
return moduleOrder;
}
/**
* @param moduleOrder The moduleOrder to set.
*/
public void setModuleOrder(int moduleOrder) {
this.moduleOrder = moduleOrder;
}
/**
* @return Returns the hidden.
* @hibernate.property column = "ishidden"
*/
public boolean isHidden() {
return hidden;
}
/**
* @param hidden The hidden to set.
*/
public void setHidden(boolean hidden) {
this.hidden = hidden;
}
/**
* @return Returns the nonPermit.
* @hibernate.property column = "isnonpermit"
*/
public boolean isNonPermit() {
return nonPermit;
}
/**
* @param nonPermit The nonPermit to set.
*/
public void setNonPermit(boolean nonPermit) {
this.nonPermit = nonPermit;
}
/**
* @return Returns the parentId.
* @hibernate.many-to-one column="parentid"
* class="net.xsbn.stride.model.realm.Module"
*/
public Module getParent() {
return parent;
}
/**
* @param parentId The parentId to set.
*/
public void setParent(Module parentId) {
this.parent = parentId;
}
/**
* @return Returns the operators.
* @hibernate.set table="usr_operator_module" lazy="true"
* @hibernate.collection-key column="moduleid"
* @hibernate.collection-many-to-many column="userid"
* class="net.xsbn.stride.model.realm.Operator"
*/
public Set getOperators() {
return operators;
}
/**
* @param operators The operators to set.
*/
public void setOperators(Set operators) {
this.operators = operators;
}
/**
* @return Returns the groups.
* @hibernate.set table="usr_group_module" lazy="true"
* @hibernate.collection-key column="moduleid"
* @hibernate.collection-many-to-many column="groupid"
* class="net.xsbn.stride.model.realm.Group"
*/
public Set getGroups() {
return groups;
}
/**
* @param groups The groups to set.
*/
public void setGroups(Set groups) {
this.groups = groups;
}
/**
* @return Returns the catalog.
* @hibernate.many-to-one column="catalogid"
* class="net.xsbn.stride.model.realm.Catalog"
*/
public Catalog getCatalog() {
return catalog;
}
/**
* @param catalog The catalog to set.
*/
public void setCatalog(Catalog catalog) {
this.catalog = catalog;
}
public String toString() {
return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
.append(this.id)
.append(this.moduleName)
.toString();
}
public boolean equals(Object o) {
try {
Module c = (Module) o;
return new EqualsBuilder()
.append(this.id, c.id)
.append(this.moduleName, c.moduleName)
.isEquals();
}
catch(Exception ex) {
//ex.printStackTrace();
return false;
}
}
public int hashCode() {
return new HashCodeBuilder()
.append(this.id)
.append(this.moduleName)
.toHashCode();
}
/* (non-Javadoc)
* @see java.lang.Comparable#compareTo(java.lang.Object)
*/
public int compareTo(Object o) {
Module m = (Module) o;
return new CompareToBuilder()
.append(this.moduleOrder, m.moduleOrder)
.toComparison();
}
/**
* @return Returns the helpUrl.
* @hibernate.property column="helpurl"
*/
public String getHelpUrl() {
return helpUrl;
}
/**
* @param helpUrl The helpUrl to set.
*/
public void setHelpUrl(String helpUrl) {
this.helpUrl = helpUrl;
}
}
<set
name="operators"
table="usr_operator_module"
lazy="true"
inverse="false"
cascade="none"
sort="unsorted"
>
<key
column="moduleid"
>
</key>
<many-to-many
class="net.xsbn.stride.model.realm.Operator"
column="userid"
outer-join="auto"
/>
</set>
<set
name="groups"
table="usr_group_module"
lazy="true"
inverse="false"
cascade="none"
sort="unsorted"
>
<key
column="moduleid"
>
</key>
<many-to-many
class="net.xsbn.stride.model.realm.Group"
column="groupid"
outer-join="auto"
/>
</set>