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;
    }

    }

  • 相关阅读:
    css清除浮动
    vue在v-for循环中绑定v-model
    Element UI 数字输入框组件添加鼠标滚动事件
    vue-cli搭建vue开发环境
    vue组件通信
    H5新增的postMessage跨域解决方案Demo
    零碎方法笔记
    django中操作cookie与session
    python中装饰器修复技术
    django中orm的批量操作
  • 原文地址:https://www.cnblogs.com/taoweiji/p/3314694.html
Copyright © 2011-2022 走看看