« | August 2025 | » | 日 | 一 | 二 | 三 | 四 | 五 | 六 | | | | | | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | | | | | | | |
| 公告 |
戒除浮躁,读好书,交益友 |
Blog信息 |
blog名称:邢红瑞的blog 日志总数:523 评论数量:1142 留言数量:0 访问次数:9691799 建立时间:2004年12月20日 |

| |
[orm]hibernate对oracle的clob操作 心得体会
邢红瑞 发表于 2004/12/21 9:43:08 |
给大家一个例子
content.xml
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 2.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd"> <hibernate-mapping> <class name="oracle.Content" table="Content"> <id name="code" column="code" type="string" length="20"> <generator class="assigned"/> </id> <property name="title" column="title" type="string" length="100"/> <property name="annextitle" column="annextitle" type="string" length="100"/> <property name="comefrom" column="comefrom" type="string" length="100"/> <property name="author" column="author" type="string" length="100"/> <property name="content" column="content" type="clob" update="true" insert="true" /> </class> </hibernate-mapping>
content.java
package oracle;
import java.io.Serializable; import oracle.sql.*;import java.sql.Clob;
public class Content implements Serializable {
/** identifier field */ private String code;
/** nullable persistent field */ private String title;
/** nullable persistent field */ private String annextitle;
/** nullable persistent field */ private String comefrom;
/** nullable persistent field */ private String author;
private Clob content;
/** default constructor */ public Content() { } public Clob getContent() { return this.content; }
public void setContent( Clob content) { this.content = content; }
public String getCode() { return this.code; }
public void setCode( String code) { this.code = code; }
public String getTitle() { return this.title; }
public void setTitle( String title) { this.title = title; }
public String getAnnextitle() { return this.annextitle; }
public void setAnnextitle( String annextitle) { this.annextitle = annextitle; }
public String getComefrom() { return this.comefrom; }
public void setComefrom( String comefrom) { this.comefrom = comefrom; }
public String getAuthor() { return this.author; }
public void setAuthor( String author) { this.author = author; }
}测试代码
test.java
package oracle;
import junit.framework.TestCase;import net.sf.hibernate.*;import net.sf.hibernate.cfg.Configuration;import net.sf.hibernate.tool.hbm2ddl.SchemaExport;import oracle.sql.CLOB;
import java.io.Writer;
public class test extends TestCase{ private static SessionFactory _sessions = null;
public void testCreate() { try { Configuration cfg = new Configuration().configure("/xhr.hbm.xml"); SchemaExport dbExport = new SchemaExport(cfg); dbExport.create(true, true);
_sessions = cfg.buildSessionFactory(); } catch (MappingException e) { e.printStackTrace(); } catch (HibernateException e) { e.printStackTrace(); } }
public void testAdd() { try { Configuration conf = new Configuration().configure("/xhr.hbm.xml"); _sessions = conf.buildSessionFactory(); Session hSessions = _sessions.openSession(); Transaction tx = hSessions.beginTransaction(); Content con = new Content(); con.setCode("2004-12-20"); con.setTitle("IBM.WEBSPHERE.APPLICATION.SERVER.V6.0"); con.setAnnextitle("IBM.WEBSPHERE.APPLICATION.SERVER.V6.0"); con.setAuthor("IBM"); con.setComefrom("IBM"); con.setContent(Hibernate.createClob(" ")); hSessions.save(con); hSessions.flush();
hSessions.refresh(con, LockMode.UPGRADE); CLOB clob = (CLOB) con.getContent(); Writer out = clob.getCharacterOutputStream(); StringBuffer sb = new StringBuffer(); for (int i = 0; i < 1000; i++) { sb.append("那里有下载"); } out.write(sb.toString()); out.close();
tx.commit(); hSessions.close();
} catch (Exception e) { e.printStackTrace(); }
}
}
xhr.hbm.xml
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN" "http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd">
<hibernate-configuration> <session-factory> <property name="dialect">net.sf.hibernate.dialect.OracleDialect</property> <property name="connection.driver_class">oracle.jdbc.driver.OracleDriver</property> <property name="connection.url">jdbc:oracle:thin:@192.168.13.4:1521:hong</property> <property name="connection.username">system</property> <property name="connection.password">manager</property> <mapping resource="oracle/Content.xml"/> </session-factory>
</hibernate-configuration> |
|
回复:hibernate对oracle的clob操作 心得体会
大灰狼(游客)发表评论于2007/7/2 12:10:06 |
为什么我在调试CLOB clob = (CLOB) con.getContent();总是出现
java.lang.ClassCastException错误?? |
|
回复:hibernate对oracle的clob操作 心得体会
aop(游客)发表评论于2005/12/14 13:12:30 |
|
回复:hibernate对oracle的clob操作 心得体会
OMG(游客)发表评论于2005/12/14 10:51:18 |
java.lang.ClassCastException!!!!!
知道什么意思么?
转型错误 |
|
回复:hibernate对oracle的clob操作 心得体会
OMG(游客)发表评论于2005/12/13 15:55:35 |
|
回复:hibernate对oracle的clob操作 心得体会
awk(游客)发表评论于2005/10/21 13:57:02 |
|
回复:hibernate对oracle的clob操作 心得体会
suu(游客)发表评论于2005/10/20 17:09:15 |
楼主在Content 中定义的content为java.sql.Clob
而 CLOB clob = (CLOB) con.getContent();中使用的是oracle.sql.CLOB 不会有问题吗?
|
|
回复:hibernate对oracle的clob操作 心得体会
飞翔(游客)发表评论于2005/10/12 13:35:10 |
楼主注意拉,要看到这条留言啊!!!! :)
CLOB是可以,而且用spring封装后会发现更简单,只要 setTheClob(Clob clob)就可以了
但是我用Blob却不行,不知道楼主有什么好的方法处理?(Hibernate或spring+Hibernate)
期待楼主的答复 E-mail: ytfei2003@yahoo.com.cn |
|
回复:hibernate对oracle的clob操作 心得体会
阿兰(游客)发表评论于2005/6/7 15:07:35 |
|
回复:hibernate对oracle的clob操作 心得体会
东东(游客)发表评论于2005/1/24 16:51:34 |
|
回复:hibernate对oracle的clob操作 心得体会
agile(游客)发表评论于2004/12/21 10:18:31 |
|
|