Hibernate3.x 中BLOB、CLOB 注解配置写法
在hibernate Annotation中,实体BLOB、CLOB类型的注解与普通的实体属性有些不同,具体操作如下:
import javax.persistence.Basic; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.FetchType; import javax.persistence.Id; import javax.persistence.Lob; import javax.persistence.Table; @Entity @Table(name = "T_USER", schema = "TRS_CMS") public class TUser implements java.io.Serializable { // Fields private Long id; private String name; //CLOB类型,类型声明为String private String introduction; //BLOB类型,类型声明为byte[]: private byte[] icon; // Constructors /** default constructor */ public TUser() { } // Property accessors @Id @Column(name = "ID", unique = true, nullable = false, precision = 22, scale = 0) public Long getId() { return this.id; } public void setId(Long id) { this.id = id; } @Column(name = "NAME", length = 40) public String getName() { return this.name; } public void setName(String name) { this.name = name; } //--============== 华丽的分割线================================ @Lob @Basic(fetch = FetchType.EAGER) @Column(name = "INTRODUCTION", columnDefinition = "CLOB",nullable=true) public String getIntroduction() { return this.introduction; } public void setIntroduction(String introduction) { this.introduction = introduction; } //--============== 华丽的分割线================================ @Lob @Basic(fetch = FetchType.LAZY) @Column(name = "ICON", columnDefinition = "BLOB",nullable=true) public byte[] getIcon() { return this.icon; } public void setIcon(byte[] icon) { this.icon = icon; } }