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 type=”yes_no” />。如果你的class中用的boolean,数据库中用的number,把映射文件中property的type写成byte,数据库保存的会是1和0,执行hql时,hibernate会把1和true,0和false互相转换,<property 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;}

}

享受每一刻的感觉,欣赏每一处的风景,这就是人生。

hibernate 注解 boolean问题解决方案

相关文章:

你感兴趣的文章:

标签云: