In order to remove few special characters coming from my host database tables into my application, I had to create my own datatype.
@Column(name="LAST_UPDATED_BY", nullable=false, length=24)
@Type(type="com.xx.CleanedString")
public String getLastUpdatedBy() {
return this.lastUpdatedBy;
}
public void setLastUpdatedBy(String lastUpdatedBy) {
this.lastUpdatedBy = lastUpdatedBy;
}
CleanedString implements UserType whose sqlTypes() is defined as an int[] { Types.CHAR }. Basically it rebuilds String after iterating the char array and filtering it out the special characters.
public int[] sqlTypes() {
return new int[] { Types.CHAR };
}
Application works perfectly fine but I am having problem running my DBUnit. When Hibernate creates the table in HSQLDB (I have hibernate.hbm2ddl.auto set to create-drop), it is creating a column of type CHARACTER with length as 1. It is ignoring the length attribute of my @column specified 24 above.
Is there a way to specify column length in this scneraio?
Try setting it to
Types.VARCHAR