You should use the @TypeDefs, @Type and @Column(columnDefinition=chkpass) annotations in your class. Also, you will have to specify how to handle the chkpass for hibernate with a class that extends org.hibernate.usertype.UserType. You can see an example in
my blog. Here is the DTO Example:
Code:
@TypeDefs({ @TypeDef(name="chkpass", typeClass=com.dtorres.customTypes.Chkpass.class) })
@Entity
@Table(name="idm_user", uniqueConstraints = @UniqueConstraint(columnNames = { "user_name" }))
public class User {
@Id
@Column(name="user_id", insertable=false, updatable=false)
@SequenceGenerator(name = "user_id_seq", sequenceName = "idm_user_user_id_seq")
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "user_id_seq")
private long userId;
@Column(name="user_name")
private String userName;
@Column(name="password", columnDefinition="chkpass", updatable=false, nullable=false)
@Type(type = "chkpass")
private String password;...
And part of the custom type:
Code:
public class Chkpass implements UserType {
@Override
public Object nullSafeGet(ResultSet inResultSet, String[] names, Object o)
throws HibernateException, SQLException {
Object tmp = inResultSet.getObject(names[0]);
return inResultSet.wasNull() ? null : tmp.toString();
}
@Override
public void nullSafeSet(PreparedStatement inPreparedStatement, Object o,
int i) throws HibernateException, SQLException {
if (o == null)
inPreparedStatement.setNull(i, Types.VARCHAR);
else
inPreparedStatement.setObject(i, o, Types.OTHER);
}...
.
This worked for me just fine, but the chkpass has some limitations, like when starting a password with colon ( : ).