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