| 发表于:2007-07-26 08:35:14 楼主 |
我在使用hibernate插入数据的时候出现异常错误 java.lang.long 而实际上数据却已经插入到数据库中 系统采用ssh框架 下面是类的映射文件 <?xml version= "1.0 " encoding= "utf-8 "?> <!doctype hibernate-mapping public "-//hibernate/hibernate mapping dtd 3.0//en " "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd "> <!-- mapping file autogenerated by myeclipse - hibernate tools --> <hibernate-mapping> <class name= "com.ffcs.lsoc.bo.knowledgeinfo " table= "knowledge_info " schema= "ffcsnss "> <id name= "knowledgeid " type= "java.lang.long "> <column name= "knowledgeid " precision= "22 " scale= "0 " /> <generator class= "sequence " > <param name= "sequence "> seq_knowledge_info </param> </generator> </id> <property name= "nodeid " type= "java.lang.long "> <column name= "nodeid " precision= "22 " scale= "0 " /> </property> <property name= "title " type= "java.lang.string "> <column name= "title " length= "300 " /> </property> <property name= "range " type= "java.lang.string "> <column name= "range " length= "100 " /> </property> <property name= "keyword " type= "java.lang.string "> <column name= "keyword " length= "200 " /> </property> <property name= "keyword1 " type= "java.lang.string "> <column name= "keyword1 " length= "200 " /> </property> <property name= "keyword2 " type= "java.lang.string "> <column name= "keyword2 " length= "200 " /> </property> <property name= "child " type= "java.lang.string "> <column name= "child " length= "100 " /> </property> <property name= "brief " type= "java.lang.string "> <column name= "brief " length= "2048 " /> </property> <property name= "content " type= "com.ffcs.lsoc.bo.type.stringclobtype "> <column name= "content " /> </property> </class> </hibernate-mapping> 其中字段content在数据库中是clob类型 类com.ffcs.lsoc.bo.type.stringclobtype用来解决 clob类型操作问题 package com.ffcs.lsoc.bo.type; import java.io.ioexception; import java.io.reader; import java.io.serializable; import java.io.stringreader; import java.sql.preparedstatement; import java.sql.resultset; import java.sql.sqlexception; import java.sql.types; import org.hibernate.hibernateexception; import org.hibernate.usertype.usertype; public class stringclobtype implements usertype { public object assemble(serializable arg0, object arg1) throws hibernateexception { // todo auto-generated method stub return null; } public object deepcopy(object value) throws hibernateexception { if (value == null) return null; return new string((string) value); } public serializable disassemble(object arg0) throws hibernateexception { // todo auto-generated method stub return null; } public boolean equals(object x, object y) throws hibernateexception { return ( x == y) ¦ ¦ ( x != null && y != null && (x.equals(y))); } public int hashcode(object arg0) throws hibernateexception { // todo auto-generated method stub return 0; } public boolean ismutable() { return false; } public object nullsafeget(resultset rs, string[] names, object owner) throws hibernateexception, sqlexception { string result = null; reader reader = rs.getcharacterstream(names[0]); if (reader != null) { stringbuffer sb = new stringbuffer(); try { char[] charbuf = new char[4096]; for (int i = reader.read(charbuf); i > 0; i= reader.read(charbuf)) { sb.append(charbuf, 0, i); } result = sb.tostring(); }catch (ioexception ioe) { } } return result; } public void nullsafeset(preparedstatement st, object value, int index) throws hibernateexception, sqlexception { if(value != null) { stringreader r = new stringreader((string)value); st.setcharacterstream(index, r, ((string)value).length() ); }else { st.setnull(index, sqltypes()[0]); } } public object replace(object arg0, object arg1, object arg2) throws hibernateexception { // todo auto-generated method stub return null; } public class returnedclass() { return string.class; } public int[] sqltypes() { return new int[] { types.clob }; } } |
|
|
|
|