phewataal
phewataal

Reputation: 1117

specifying Column Length for columns of @Type(type=xxx)

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?

Upvotes: 1

Views: 863

Answers (1)

Bozho
Bozho

Reputation: 597096

Try setting it to Types.VARCHAR

Upvotes: 1

Related Questions