content.xml
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
"-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd">