zoukankan      html  css  js  c++  java
  • hibernate 注解 boolean问题解决方案

    1.JPA本身是不支持boolean。可以用Hibernater自带的标签.修改如下.

    @Column(name = "manager_log")
    @org.hibernate.annotations.Type(type="yes_no")
    private boolean manageLog = false; // 能否管理系统日志
    数据库不认识boolean,用其他类型代替,number或者varchar
    如果你的class中用的boolean,数据库中用varchar,把映射文件中property的type写成yes_no,数据库保存的会是Y和N,执行hql时,hibernate会把Y和true,N和false相互转换,<property name="visible" type="yes_no" />。
    如果你的class中用的boolean,数据库中用的number,把映射文件中property的type写成byte,数据库保存的会是1和0,执行hql时,hibernate会把1和true,0和false互相转换,<property name="visible" type="byte" />。


    给你一个例子:

    @Entity
    @Table(name = "question", catalog = "table")
    public class Question implements java.io.Serializable {

    // Fields

    @Id
    @GeneratedValue(strategy = IDENTITY)
    @Column(name = "id", unique = true, nullable = false)
    private Integer id;
    @Column(name = "untreated")
    @org.hibernate.annotations.Type(type="yes_no")
    private Boolean untreated;

    public Integer getId() {
    return this.id;
    }

    public void setId(Integer id) {
    this.id = id;
    }

    public Boolean getUntreated() {
    return untreated;
    }

    public void setUntreated(Boolean untreated) {
    this.untreated = untreated;
    }

    }

  • 相关阅读:
    mvn编译
    国庆续写商品管理系统(二)
    Flask中多APP应用以及admin后台系统
    Bzoj3289 Mato的文件管理
    洛谷P2888 [USACO07NOV]牛栏Cow Hurdles
    POJ1988 Cube Stacking
    Bzoj3060 [Poi2012]Tour de Byteotia
    Bzoj3038 上帝造题的七分钟2 线段树
    Bzoj3038 上帝造题的七分钟2 并查集
    TYVJ1716 上帝造题的七分钟
  • 原文地址:https://www.cnblogs.com/taoweiji/p/3314694.html
Copyright © 2011-2022 走看看