使用Hibernate 操作Clob成功小记

使用Hibernate 操作Clob成功小记

说明:

① 代码我已经测试成功,如下代码,只供借鉴。

② 我的开发环境是:JBuilder2006+Oracle9i

③ 文章如需引用转载,请注明出处

一、创建数据库

我使用的创建数据库的代码如下:

DROP TABLE INDUSTRYTYPE;

CREATE TABLE INDUSTRYTYPE

(

TYPEID NUMBER(10) PRIMARY KEY,

TYPENAME VARCHAR2(100) NOT NULL,

DESCRIPTION VARCHAR2(100) NOT NULL

);

DROP SEQUENCE INDUSTRYTYPE_SEQ;

CREATE SEQUENCE INDUSTRYTYPE_SEQ INCREMENT BY 1 START WITH 4000;

DROP TABLE INDUSTRY;

CREATE TABLE INDUSTRY

(

INDU_ID NUMBER(10) PRIMARY KEY,

ADMIN_ID NUMBER(10) NOT NULL,

TYPEID NUMBER(10) NOT NULL,

ISSUEDATE DATE NOT NULL,

CONTENT CLOB

);

DROP SEQUENCE INDUSTRY_SEQ;

CREATE SEQUENCE INDUSTRY_SEQ INCREMENT BY 1 START WITH 1;

二、 Eclipse中创建POJO和映射文件

我的代码如下:

1. AbstractIndustry.java

/*

* WARNING: DO NOT EDIT THIS FILE. This is a generated file that is synchronized

* by MyEclipse Hibernate tool integration.

*

* Created Tue Feb 28 16:38:20 CST 2006 by MyEclipse Hibernate Tool.

*/

import java.io.Serializable;

/**

* A class that represents a row in the INDUSTRYTYPE table.

* You can customize the behavior of this class by editing the class, {@link Industrytype()}.

* WARNING: DO NOT EDIT THIS FILE. This is a generated file that is synchronized

* by MyEclipse Hibernate tool integration.

*/

public abstract class AbstractIndustrytype

implements Serializable

{

/** The cached hash code value for this instance. Settting to 0 triggers re-calculation. */

private int hashValue = 0;

/** The composite primary key value. */

private java.lang.Long typeid;

/** The value of the simple typename property. */

private java.lang.String typename;

/** The value of the simple description property. */

private java.lang.String description;

/**

* Simple constructor of AbstractIndustrytype instances.

*/

public AbstractIndustrytype()

{

}

/**

* Constructor of AbstractIndustrytype instances given a simple primary key.

* @param typeid

*/

public AbstractIndustrytype(java.lang.Long typeid)

{

this.setTypeid(typeid);

}

/**

* Return the simple primary key value that identifies this object.

* @return java.lang.Long

*/

public java.lang.Long getTypeid()

{

return typeid;

}

/**

* Set the simple primary key value that identifies this object.

* @param typeid

*/

public void setTypeid(java.lang.Long typeid)

{

this.hashValue = 0;

this.typeid = typeid;

}

/**

* Return the value of the TYPENAME column.

* @return java.lang.String

*/

public java.lang.String getTypename()

{

return this.typename;

}

/**

* Set the value of the TYPENAME column.

* @param typename

*/

public void setTypename(java.lang.String typename)

{

this.typename = typename;

}

/**

* Return the value of the DESCRIPTION column.

* @return java.lang.String

*/

public java.lang.String getDescription()

{

return this.description;

}

/**

* Set the value of the DESCRIPTION column.

* @param description

*/

public void setDescription(java.lang.String description)

{

this.description = description;

}

/**

* Implementation of the equals comparison on the basis of equality of the primary key values.

* @param rhs

* @return boolean

*/

public boolean equals(Object rhs)

{

if (rhs == null)

return false;

if (! (rhs instanceof Industrytype))

return false;

Industrytype that = (Industrytype) rhs;

if (this.getTypeid() == null || that.getTypeid() == null)

return false;

return (this.getTypeid().equals(that.getTypeid()));

}

/**

* Implementation of the hashCode method conforming to the Bloch pattern with

* the exception of array properties (these are very unlikely primary key types).

* @return int

*/

public int hashCode()

{

if (this.hashValue == 0)

{

int result = 17;

int typeidValue = this.getTypeid() == null ? 0 : this.getTypeid().hashCode();

result = result * 37 + typeidValue;

this.hashValue = result;

}

return this.hashValue;

}

}

2. Industrytype.java

/*

* Created Tue Feb 28 16:38:20 CST 2006 by MyEclipse Hibernate Tool.

*/

import java.io.Serializable;

import java.util.Set;

/**

* A class that represents a row in the 'INDUSTRYTYPE' table.

* This class may be customized as it is never re-generated

* after being created.

*/

public class Industrytype extends AbstractIndustrytype implements Serializable {

/**

* 存储某一种类型的所有行业交流

*/

private Set induSet;

/**

* Simple constructor of Industrytype instances.

*/

public Industrytype() {

}

/**

* Constructor of Industrytype instances given a simple primary key.

* @param typeid

*/

public Industrytype(java.lang.Long typeid) {

super(typeid);

}

public void setInduSet(Set induSet) {

this.induSet = induSet;

}

public Set getInduSet() {

return induSet;

}

/* Add customized code below */

}

3. Industrytype.hbm.xml

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"

"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<!-- DO NOT EDIT: This is a generated file that is synchronized -->

<!-- by MyEclipse Hibernate tool integration. -->

<!-- Created Tue Feb 28 16:38:20 CST 2006 -->

<hibernate-mapping package="com.scenechina.vr.model">

<class name="Industrytype" table="INDUSTRYTYPE">

<id name="typeid" column="TYPEID" type="java.lang.Long">

<generator class="assigned"/>

</id>

<property name="typename" column="TYPENAME" type="java.lang.String" not-null="true"/>

<property name="description" column="DESCRIPTION" type="java.lang.String" not-null="true"/>

<set name="induSet" cascade="all" inverse="true" lazy="false" table="Industry">

<key column="typeid"/>

<one-to-many class="Industry"/>

</set>

</class>

</hibernate-mapping>

4. AbstractIndustry.java

/*

* WARNING: DO NOT EDIT THIS FILE. This is a generated file that is synchronized

* by MyEclipse Hibernate tool integration.

*

* Created Tue Feb 28 16:38:20 CST 2006 by MyEclipse Hibernate Tool.

*/

import java.io.Serializable;

import java.sql.Clob;

/**

* A class that represents a row in the INDUSTRY table.

* You can customize the behavior of this class by editing the class, {@link Industry()}.

* WARNING: DO NOT EDIT THIS FILE. This is a generated file that is synchronized

* by MyEclipse Hibernate tool integration.

*/

public abstract class AbstractIndustry implements Serializable {

/** The cached hash code value for this instance. Settting to 0 triggers re-calculation. */

private int hashValue = 0;

/** The composite primary key value. */

private java.lang.Long induId;

/** The value of the simple adminId property. */

private java.lang.Long adminId;

/** The value of the simple typeid property. */

private java.lang.Long typeid;

/** The value of the simple issuedate property. */

private java.util.Date issuedate;

/** The value of the simple content property. */

private Clob content;

/** the value of the title of the industry */

private String title;

/**

* Simple constructor of AbstractIndustry instances.

*/

public AbstractIndustry() {

}

/**

* Constructor of AbstractIndustry instances given a simple primary key.

* @param induId

*/

public AbstractIndustry(java.lang.Long induId) {

this.setInduId(induId);

}

/**

* Return the simple primary key value that identifies this object.

* @return java.lang.Long

*/

public java.lang.Long getInduId() {

return induId;

}

/**

* Set the simple primary key value that identifies this object.

* @param induId

*/

public void setInduId(java.lang.Long induId) {

this.hashValue = 0;

this.induId = induId;

}

/**

* Return the value of the ADMIN_ID column.

* @return java.lang.Long

*/

public java.lang.Long getAdminId() {

return this.adminId;

}

/**

* Set the value of the ADMIN_ID column.

* @param adminId

*/

public void setAdminId(java.lang.Long adminId) {

this.adminId = adminId;

}

/**

* Return the value of the TYPEID column.

* @return java.lang.Long

*/

public java.lang.Long getTypeid() {

return this.typeid;

}

/**

* Set the value of the TYPEID column.

* @param typeid

*/

public void setTypeid(java.lang.Long typeid) {

this.typeid = typeid;

}

/**

* Return the value of the ISSUEDATE column.

* @return java.util.Date

*/

public java.util.Date getIssuedate() {

return this.issuedate;

}

/**

* Set the value of the ISSUEDATE column.

* @param issuedate

*/

public void setIssuedate(java.util.Date issuedate) {

this.issuedate = issuedate;

}public String getTitle() {

return title;

}

public Clob getContent() {

return content;

}

public void setTitle(String title) {

this.title = title;

}

public void setContent(Clob content) {

this.content = content;

}

/**

* Implementation of the equals comparison on the basis of equality of the primary key values.

* @param rhs

* @return boolean

*/

public boolean equals(Object rhs) {

if (rhs == null) {

return false;

}

if (!(rhs instanceof Industry)) {

return false;

}

Industry that = (Industry) rhs;

if (this.getInduId() == null || that.getInduId() == null) {

return false;

}

return (this.getInduId().equals(that.getInduId()));

}

/**

* Implementation of the hashCode method conforming to the Bloch pattern with

* the exception of array properties (these are very unlikely primary key types).

* @return int

*/

public int hashCode() {

if (this.hashValue == 0) {

int result = 17;

int induIdValue = this.getInduId() == null ? 0 :

你可能感兴趣的:(java,eclipse,sql,Hibernate,MyEclipse)