![](/img/trans.png)
[英]How to insert Large clob data(>4K characters) in oracle 10g using jdbc
[英]Saving data into Clob using Hibernate in Oracle 10g
我在Hibernate中有一個帶有java.sql.Clob
列的表
hbm
文件:
<class name="com.model.ClobModel" table="table1">
<id name="id" column="id">
<generator class="assigned"></generator>
</id>
<property name="clobData" type="clob">
<column name="ClobData"></column>
</property>
這是ClobModel
:
private Integer id;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
private Clob clobData;
public Clob getClobData() {
return clobData;
}
public void setClobData(Clob clobData) {
this.clobData = clobData;
}
當我在休眠中嘗試這個時:
SessionFactory sf = new Configuration().configure("clob.cfg.xml").buildSessionFactory();
Session sess = sf.openSession();
ClobModel cb = new ClobModel();
cb.setId(101);
try {
// getClobData() method returns String, trying to convert it into java.sql.Clob and then assign it to the model
cb.setClobData(new javax.sql.rowset.serial.SerialClob(new ClobInsert().getClobData().toCharArray()));
} catch (SerialException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
sess.save(cb);
sess.flush();
System.out.println("Exit!!!");
我得到一個例外:
javax.sql.rowset.serial.SerialClob cannot be cast to oracle.sql.CLOB
上面提到的所有Clob
都是java.sql.Clob
類型。
不確定如何將String
轉換為java.sql.Clob
?
您需要將字段的類型顯式映射到java.sql.Clob
。
<property
name="data"
type="java.sql.Clob"
update="true"
insert="true"
column="data"
/>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.