Hibernate Annotation问题解决方案详解

来源:岁月联盟 编辑:zhuzhu 时间:2009-09-23

本文向大家介绍Hibernate Annotation,可能好多人还不了解Hibernate Annotation,没有关系,看完本文你肯定有不少收获,希望本文能教会你更多东西。

在Hibernate Annotation中,实体BLOB、CLOB类型的注解与普通的实体属性有些不同,具体操作如下:BLOB类型,类型声明为byte[]:

  1. private byte[] content; 

注解:

  1. @Lob  
  2. @Basic(fetch = FetchType.LAZY)  
  3. @Column(name = "CONTENT", columnDefinition = "BLOB",nullable=true)  
  4. public byte[] getContent() {  
  5. return this.content;  
  6. }  
  7.  
  8. public void setContent(byte[] content) {  
  9. this.content = content;  

CLOB类型,类型声明为String即可:

  1. private String remark; 

注解:

  1. @Lob  
  2. @Basic(fetch = FetchType.EAGER)  
  3. @Column(name="REMARK", columnDefinition="CLOB", nullable=true)  
  4. public String getRemark() {  
  5. return this.remark;  
  6. }  
  7.  
  8. public void setRemark(String recvdocRemark) {  
  9. this.remark = remark;  

按照以上的设置实体类的注解就搞定了。以上介绍Hibernate Annotation中,实体BLOB、CLOB类型的注解与普通的实体属性有些不同。