Hibernate 为@Type(Type=xxx)的列指定列长度
为了将主机数据库表中的一些特殊字符删除到应用程序中,我必须创建自己的数据类型Hibernate 为@Type(Type=xxx)的列指定列长度,hibernate,annotations,hsqldb,dbunit,Hibernate,Annotations,Hsqldb,Dbunit,为了将主机数据库表中的一些特殊字符删除到应用程序中,我必须创建自己的数据类型 @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
@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}
。基本上,它在迭代字符数组并过滤掉特殊字符后重建字符串
public int[] sqlTypes() {
return new int[] { Types.CHAR };
}
应用程序运行得很好,但我在运行DBUnit
时遇到问题。当Hibernate在HSQLDB中创建表时(我将Hibernate.hbm2ddl.auto
设置为create drop
),它正在创建一个长度为1的CHARACTER
类型的列。它将忽略上面指定的我的@列的长度属性
有没有办法在这个脚本中指定列长度?尝试将其设置为尝试将其设置为在hSQLDB中创建表时,它工作正常,但当它与DB2数据库的字符(n)交互时会发生什么情况不是varchar数据类型的数据类型。它在hSQLDB中创建表期间工作正常,但当它与不是varchar数据类型的DB2数据库字符(n)数据类型交互时会发生什么情况。