Hibernate3.X实现基于CLOB字段类型的注解方式:

一:Hibernate3.X实现基于CLOB字段类型的注解方式的例子:下面直接上代码:


二:UserInfo.java

package cn.gov.csrc.cms.model;

import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Lob;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

import oracle.sql.CLOB;

/**
* File:    UserInfo.java
* Author:  admin
* Version: 1.0
* Date:    2014/08/13
* Modify:
* Description: 系统用户表
* Copyright: sinodata
*/
@Entity
@Table(name = "tb_cms_user")
public class UserInfo {

	private Integer userId;// ID

	private String userName;// 登录名

	private String passWd;// 登录密码

	private String realName;// 用户姓名

	private String phone;// 电话

	private String dept;// 部门

	private String post;// 岗位
	
	private CLOB fieldNames;// 存放xml文本文件的字段

	@Id
	@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "SEQ_STORE")
	@SequenceGenerator(name = "SEQ_STORE", sequenceName = "USER_SEQ", allocationSize = 1)
	public Integer getUserId() {
		return userId;
	}

	public void setUserId(Integer userId) {
		this.userId = userId;
	}

	@Column(name = "USERNAME", nullable = false, length = 30)
	public String getUserName() {
		return userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

	@Column(name = "PASSWD", nullable = false, length = 100)
	public String getPassWd() {
		return passWd;
	}

	public void setPassWd(String passWd) {
		this.passWd = passWd;
	}

	@Column(name = "REALNAME", length = 10)
	public String getRealName() {
		return realName;
	}

	public void setRealName(String realName) {
		this.realName = realName;
	}

	@Column(name = "PHONE", length = 15)
	public String getPhone() {
		return phone;
	}

	public void setPhone(String phone) {
		this.phone = phone;
	}

	@Column(name = "DEPT", length = 10)
	public String getDept() {
		return dept;
	}

	public void setDept(String dept) {
		this.dept = dept;
	}

	@Column(name = "POST", length = 10)
	public String getPost() {
		return post;
	}

	public void setPost(String post) {
		this.post = post;
	}

	@Lob 
	@Basic(fetch = FetchType.EAGER) 
	@Column(name="FIELDNAMES", columnDefinition="CLOB", nullable=true)
	public CLOB getFieldNames() {
		return fieldNames;
	}

	public void setFieldNames(CLOB fieldNames) {
		this.fieldNames = fieldNames;
	}
	
	
}

三:Oracle中直接通过sql插入CLOB字段类型的数据:

/* Formatted on 2014/8/19 15:45:29 (QP5 v5.115.810.9015) */
INSERT INTO TB_CMS_USER (
                            USERID,
                            DEPT,
                            PASSWD,
                            PHONE,
                            POST,
                            REALNAME,
                            USERNAME,
                            FIELDNAMES
           )
  VALUES   (
               1,
               '开发支持部',
               '123456789',
               '18611966723',
               'Java工程师',
               '工程师',
               'zhaoxinguo',
               '<?xml version="1.0" encoding="UTF-8"?>
<ASUPDATA>

<MSG>  <META>    <SNDR>DC</SNDR>    <DTTM>20140714001122</DTTM>    <TYPE>FLOP</TYPE>    <STYP>FGIS</STYP>  </META>  <FLOP>    <FFID>CZ-CZ3726-D-14JUL142220-D</FFID>    <CHDT>29</CHDT>  </FLOP></MSG>
</ASUPDATA>'
           );


你可能感兴趣的:(hibernate3)