1
为了从我的主机数据库表中删除少量特殊字符到我的应用程序中,我必须创建自己的数据类型。为@Type(type = xxx)列指定列长度
@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
实现UserType
其sqlTypes()
被定义为int[] { Types.CHAR }
。基本上它会在迭代char数组并将其过滤出特殊字符之后重新生成String。
public int[] sqlTypes() {
return new int[] { Types.CHAR };
}
应用程序工作正常,但我有问题运行我的DBUnit
。当Hibernate在HSQLDB中创建表(我有hibernate.hbm2ddl.auto
设置为create-drop
)时,它创建一个长度为1的类型为CHARACTER
的列。它忽略了上面指定的我的@column
的长度属性。
有没有一种方法来指定这个分光镜的列长度?
它工作正常,但是当它与DB2数据库的字符(n)的数据类型,是不是VARCHAR数据类型进行交互时会发生什么。 – phewataal