Equals method of Embeddable object not getting called.
------------------------------------------------------
Key: HHH-2483
URL:
http://opensource.atlassian.com/projects/hibernate/browse/HHH-2483
Project: Hibernate3
Type: Bug
Components: core
Versions: 3.2.2
Environment: Hibernate 3.2.2, JavaDB
Reporter: Unnikrishnan.k.v
As a work around to issue reported in HHH-2482, I tried using a Embeddable object
*PasswordHolder* which implements correct equals method to compare char[]'s.
But even then hibernate is calling equals method of char[] instead of equals method
implemented in PasswordHolder.
I am pasting the PasswordHolder source below. To reproduce the issue,
1. create an entity with PasswordHolder as embedded field.
2. Use version number for optimistic locking.
3. Insert a row into db.
4. Now fetch this row through Hibernate entity manager.
5. After the program exits, check the version number of the accessed row.
import java.io.Serializable;
import java.sql.SQLClientInfoException;
import javax.persistence.Column;
import javax.persistence.Embeddable;
/**
*
* @author unni
*/
@Embeddable
public class PasswordHolder implements Serializable {
/** Creates a new instance of Password */
public PasswordHolder() {
}
public PasswordHolder(char[] password) {
this.password = password;
}
private char[] password;
@Column(length = 32, nullable = false)
public char[] getPassword() {
return password;
}
public void setPassword(char[] password) {
this.password = password;
}
public boolean equals(Object o) {
if (o instanceof PasswordHolder) {
AppUtil appUtil = AppUtil.getInstance();
return (0 == appUtil.compare(this.password, ((PasswordHolder)o).password));
}
return false;
}
public int hashCode() {
return password.hashCode();
}
}
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://opensource.atlassian.com/projects/hibernate/secure/Administrators....
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira