如何使用Hibernate注释将Firebird Smallint映射到布尔值?

Raf*_*ruz 2 firebird hibernate hibernate-annotations

我有一个在Firebird 2.0中运行的旧数据库,我需要将一个SmallInt列映射到一个布尔类型,当时它SmallInt = 0是False,以及何时SmallInt = 1它True.

我还需要使用Hibernate Annotations完成.

我正在使用Hibernate 3.6.

有小费吗?

提前致谢.

Raf*_*ruz 5

在搜索了一下之后,我可以org.hibernate.type.NumericBooleanType在http://docs.jboss.org/hibernate/core/3.6/reference/en-US/html/types.html#types-value-basic上找到这个hibernate类型.

我试图用这种方式绘图:

@Type(type = "org.hibernate.type.NumericBooleanType")
private Boolean field;
Run Code Online (Sandbox Code Playgroud)

但是,这没有用,因为Hibernate抛出了这个异常:

org.hibernate.HibernateException: Wrong column type in %TABLE_NAME% for column %COLUMN_NAME%. Found: smallint, expected: integer
Run Code Online (Sandbox Code Playgroud)

所以,我试图强制这个列的定义,以这种方式映射:

@Column(columnDefinition = "SMALLINT")
@Type(type = "org.hibernate.type.NumericBooleanType")
private Boolean field;
Run Code Online (Sandbox Code Playgroud)

而现在这就像一个魅力.