我有一个在 Firebird 2.0 中运行的旧数据库,我需要将 SmallInt 列映射到 bool 类型,当 SmallInt = 0
时,该类型为 False
,当 SmallInt = 1
时,它是 True
。
我还需要使用 Hibernate Annotations 来完成此操作。
我使用的是 Hibernate 3.6。
有什么建议吗?
提前致谢。
最佳答案
经过更多搜索,我可以在 http://docs.jboss.org/hibernate/core/3.6/reference/en-US/html/types.html#types-value-basic 上找到这个 hibernate 类型 org.hibernate.type.NumericBooleanType
我尝试以这种方式映射:
@Type(type = "org.hibernate.type.NumericBooleanType")
private Boolean field;
但是,这不起作用,因为 Hibernate 抛出了这个异常:
org.hibernate.HibernateException: Wrong column type in %TABLE_NAME% for column %COLUMN_NAME%. Found: smallint, expected: integer
因此,我尝试强制定义此列,以这种方式映射:
@Column(columnDefinition = "SMALLINT")
@Type(type = "org.hibernate.type.NumericBooleanType")
private Boolean field;
现在这就像一个魅力。
关于hibernate - 如何使用 Hibernate Annotations 将 Firebird Smallint 映射到 bool 值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11741895/