java.sql.Clob
我在 Hibernate 中有一个带有列的表
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
提到的都是 type java.sql.Clob
。
不知道如何转换String
成java.sql.Clob
?