Commit 1f5f62cd by Juho Juopperi

bug

1 parent 50b03a05
......@@ -6,49 +6,45 @@ import java.util.Random;
import javax.persistence.MappedSuperclass;
import javax.persistence.Transient;
import org.eclipse.persistence.annotations.OptimisticLocking;
import org.eclipse.persistence.annotations.OptimisticLockingType;
@MappedSuperclass
@OptimisticLocking(type = OptimisticLockingType.CHANGED_COLUMNS)
public abstract class EntityEquals {
@Override
public final String toString() {
return new StringBuilder(this.getClass().getCanonicalName()).append("[").append(getId()).append("]").toString();
}
@Transient
private Integer rndid;
protected abstract Object getId();
@Override
public boolean equals(Object o) {
boolean ret = false;
if (this == o) {
ret = true;
} else if (o != null && o instanceof EntityEquals && this.getClass().getCanonicalName().equals(o.getClass().getCanonicalName())) {
EntityEquals oobj = (EntityEquals) o;
if (getId() == null) {
ret = (getRndid().equals(oobj.rndid));
} else {
ret = getId().equals(oobj.getId());
}
}
return ret;
}
private Integer getRndid() {
if (rndid == null) {
Random rng = new Random(new Date().getTime());
rndid = Integer.valueOf(rng.nextInt());
}
return rndid;
}
@Override
public final int hashCode() {
return ((rndid != null || getId() == null) ? getRndid() : getId().hashCode());
}
@Override
public final String toString() {
return new StringBuilder(this.getClass().getCanonicalName()).append("[").append(getId()).append("]").toString();
}
@Transient
private Integer rndid;
protected abstract Object getId();
@Override
public boolean equals(Object o) {
boolean ret = false;
if (this == o) {
ret = true;
} else if (o != null && o instanceof EntityEquals && this.getClass().getCanonicalName().equals(o.getClass().getCanonicalName())) {
EntityEquals oobj = (EntityEquals) o;
if (getId() == null) {
ret = (getRndid().equals(oobj.rndid));
} else {
ret = getId().equals(oobj.getId());
}
}
return ret;
}
private Integer getRndid() {
if (rndid == null) {
Random rng = new Random(new Date().getTime());
rndid = Integer.valueOf(rng.nextInt());
}
return rndid;
}
@Override
public final int hashCode() {
return ((rndid != null || getId() == null) ? getRndid() : getId().hashCode());
}
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!