[英]Saving data into Clob using Hibernate in Oracle 10g
I have a table with a java.sql.Clob
column in Hibernate 我在Hibernate中有一个带有java.sql.Clob
列的表
The hbm
file: 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>
This is the ClobModel
: 这是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;
}
When I tried this in hibernate: 当我在休眠中尝试这个时:
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!!!");
I am getting an exception: 我得到一个例外:
javax.sql.rowset.serial.SerialClob cannot be cast to oracle.sql.CLOB
All the Clob
mentioned above are of type java.sql.Clob
. 上面提到的所有Clob
都是java.sql.Clob
类型。
Not sure how to convert the String
into java.sql.Clob
? 不确定如何将String
转换为java.sql.Clob
?
You need explicitly map the type of the field to 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.