I have some models that implements comparable but when i call method FINDALL(), never pass through methodcompareTo.
Anyone knows why? How can i fix this?
My Class below.
@Entity
@Table(name = "TB_UF")
public class UfBO extends _BaseModel implements Comparable<UfBO> {
private static final long serialVersionUID = -3926358646464100718L;
@Id
@Column(name = "CO_UF")
private Long id;
@Column(name = "NO_UF")
private String name;
@Column(name = "NO_SIGLA_UF")
private String uf;
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// get/set
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
public Long getId() {
return this.id;
}
public void setId(final Long id) {
this.id = id;
}
public String getName() {
return this.name;
}
public void setName(final String name) {
this.name = name;
}
public String getUf() {
return this.uf;
}
public void setUf(final String uf) {
this.uf = uf;
}
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// * @see java.lang.Object#toString()
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@Override
public String toString() {
return this.getUf();
}
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// * @see java.lang.Object#hashCode()
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result + (this.id == null ? 0 : this.id.hashCode());
return result;
}
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// * @see java.lang.Object#equals(java.lang.Object)
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@Override
public boolean equals(final Object obj) {
if (this == obj) {
return true;
}
if (!super.equals(obj)) {
return false;
}
if (this.getClass() != obj.getClass()) {
return false;
}
final UfBO other = (UfBO) obj;
if (this.id == null) {
if (other.id != null) {
return false;
}
} else if (!this.id.equals(other.id)) {
return false;
}
return true;
}
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// * @see java.lang.Comparable#compareTo(java.lang.Object)
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@Override
public int compareTo(final UfBO o) {
return StringUtil.removeSpecialsCharacters(this.getUf()).compareToIgnoreCase(StringUtil.removeSpecialsCharacters(o.getUf()));
}
}
List<ModelX> list =ModelX.findAll();
Collections.sort(list);
// list is now sorted according to the compareTo