Oracle 10+ DB - Hibernate将所有Number(1)字段解释为false

时间:2014-02-12 20:56:48

标签: java oracle hibernate hibernate-mapping

我正在尝试使用一组类别记录实现过滤方法,作为模块升级的一部分。为此,我添加了

IS_ENABLED NUMBER(1,0) 

到CATEGORY表,每行的0或1分别为false或true。

ID  NAME                DISPLAY IS_ENABLED
                        ORDER
12  Direct Mail         6       1
1   Annual reports      null    0
2   Books               1       1
3   Brochures           2       1 
4   Calendars           null    0
5   Catalogs            3       1
6   Digital Print       5       1
7   Magazines 
    (sheetfed)          8       1
8   Magazines (web)     9       1
9   Printer's own 
    promotions          10      1
10  General print       7       1

我还通过添加

修改了Hibernate配置文件
<property name="enabled" type = "boolean">
    <column name="IS_ENABLED" />
</property>

并在POJO模型中添加带有getter和setter的相应布尔字段。该模型包含toString()方法,其中包括行记录的名称,顺序和启用状态。

public class Category implements java.io.Serializable {

private long id;
private String name;
private Short displayOrder;
private boolean enabled;

    //getters and setters

    @Override
    public String toString(){
    return this.id + "\t" + this.name + "\t" + this.enabled + "\t" + this.displayOrder + "\n";
}

我的问题是toString()正在打印

Current category: 2    Books         false  1
Current category: 3    Brochures     false  2
Current category: 5    Catalogs      false  3
Current category: 6    Digital Print false  5
Current category: 12   Direct Mail   false  6
Current category: 10   General print false  7
Current category: 7    Magazines 
                       (sheetfed)    false  8
Current category: 8    Magazines 
                       (web)         false  9
Current category: 9    Printer's own 
                       promotions    false  10
Current category: 1    Annual 
                       reports       false  null
Current category: 4    Calendars     false  null

正如你所看到的,一切都是虚假的,而不是它应该是什么。要使实例enabled属性反映数据库值,需要做些什么?

0 个答案:

没有答案