Friday, May 15, 2009

A Solution for Equals and HashCode Method of Hibernate Domain Ojbect

Issue:

Solution:
every domain object extends the following object.
public abstract class BaseObject {

private String uuid = UUID.randomUUID().toString();

public String getUuid() {
return uuid;
}

public void setUuid(String uuid) {
this.uuid = uuid;
}

@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((uuid == null) ? 0 : uuid.hashCode());
return result;
}

@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
final BaseObject other = (BaseObject) obj;
if (uuid == null) {
if (other.uuid != null)
return false;
} else if (!uuid.equals(other.uuid))
return false;
return true;
}
}

1 comment:

  1. how to make a word dictionary using hash map in android kindly help us please.....

    ReplyDelete