使用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 :
分享到:
相关推荐
Hibernate存储Clob字段的方式总结涉及了在Java开发中使用Hibernate操作大型文本字段Clob的操作方法。本文主要介绍了两种操作Clob字段的方法,一种是将Clob字段直接映射为String类型,另一种是使用Clob类型进行处理。...
本文将深入探讨Hibernate如何进行BLOB和CLOB的操作,以及相关的核心概念和实践示例。 BLOB用于存储二进制数据,例如图片或文档,而CLOB则用于存储大量的字符数据,如长篇的文本内容。在数据库中,这两个类型通常...
hibernate存取oracle的clob
Hibernate也支持直接使用Clob对象进行映射,这意味着在实体类中直接使用Clob类型的字段,然后在Hibernate的映射文件中进行相应的配置。这种方式适合处理大数据量的文本,因为它允许直接与数据库的Clob类型进行交互...
Oracle数据库提供了支持Clob和Blob的接口,而Hibernate作为与数据库交互的中间层,提供了便捷的方式来操作这些大型对象。 首先,Clob类型主要用来存储大量字符数据,例如长篇的文本、XML文档等。Blob则用于存储二...
Spring和Hibernate框架结合使用可以有效地进行CLOB字段的操作。以下是实现这一功能的关键步骤和注意事项: 1. **配置SessionFactory** 在Spring配置文件中,你需要创建一个`SessionFactory` bean,同时指定一个`...
通过以上步骤,我们可以成功地在Spring与Hibernate框架中处理Oracle 10g数据库中的CLOB字段。这种方式不仅可以提高应用程序的效率,还能保证数据的完整性和一致性。此外,合理的配置和编码实践也能够进一步提升系统...
这篇博客文章“Hibernate操作Oracle中Clob、Blob字段小结”可能会探讨如何在Hibernate中有效地处理这两种类型的数据。 1. **Clob与Blob的理解**: - Clob:Clob是用于存储大量字符数据的类型,例如长篇文章、XML...
本主题“hibernate动态映射表处理Oracle的CLOB类型”主要聚焦于如何在Hibernate中有效地管理和操作CLOB字段。在Oracle 10g中,CLOB数据类型的处理有时会遇到一些挑战,尤其是在与ORM框架结合使用时。以下将详细介绍...
在Java中,Blob和Clob是JDBC API提供的接口,但在Hibernate中,我们可以通过Session对象的save()或saveOrUpdate()方法来操作这些大数据对象。 首先,我们需要在实体类中定义对应的属性。例如,对于一个包含图片信息...
hibernate Blob、Clob字段的映射的例子.数据库mysql,数据库放在文件夹里面,例子的说明文章在我的csdn blog: http://blog.csdn.net/zhengcandan
在Hibernate框架中,Clob类型的字段处理是数据库操作中的一个关键环节,尤其是在处理大量文本数据时。以下是对Oracle Clob在Hibernate中应用的详细总结: 3.1 传统的JDBC方式: 在没有使用ORM框架之前,我们通常...
这篇文章主要讲解了如何使用`JDBC`和`Hibernate`这两种不同的方式来处理`CLOB`和`BLOB`字段。 1. **数据库中的`CLOB`与`BLOB`类型** - 在MySQL中,`CLOB`对应`TEXT`类型,`BLOB`对应`BLOB`类型。 - 在DB2或Oracle...
在Java Web开发中,Hibernate是一个流行的对象关系映射(ORM)框架,它允许开发者使用面向对象的方式来操作数据库。Blob和Clob是Java中用于处理大数据类型的数据对象,Blob用于存储二进制大对象,如图片、音频或视频...
综上所述,使用Hibernate和JDBC读取Oracle数据库中的Blob数据涉及多个步骤,包括实体类的设计、数据库操作和文件流的处理。理解这些知识点对于处理大对象存储至关重要。在实际项目中,根据需求和性能考虑,选择合适...
在Hibernate,一个流行的Java对象关系映射(ORM)框架中,Blob和Clob也被广泛使用,特别是在处理大型图片、文件或长文本时。 在Hibernate和Microsoft SQL Server的环境中,Blob常用来存储图像、音频、视频等二进制...