First Friend:
The initial problems identifies and most of the cases, and report Streams Type Cannot Be used in batChing error. I used ImmutableType to define StringClobType Extends ImmutableType as follows:
Java code:
public class StringClobType extends ImmutableType {public Object get (ResultSet rs, String name) throws HibernateException, SQLException {Clob clob = rs.getClob (name); if (clob == null) {return "";} return clob.getSubString (1 , (int) clob.length ());} public void set (PreparedStatement st, Object value, int index) throws HibernateException, SQLException {StringReader r = new StringReader ((String) value); st.setCharacterStream (index, r, (String) Value) .length ());} public int SQLTYPE () {Return Types.clob;} public string getName () {return "string";} public boolean hasniceequals () {return false;} public boolean equals (Object X, Object Y) {Return ObjectUTILS.Equals (x, y); public String toXML (Object value) {return (String) value;} public Class getReturnedClass () {return Clob.class;} public Object fromStringValue (String xml) {throw new UnsupportedOperationException ();} public String toString (Object value) { Return value.toString ();}}
Use this way to handle small records (less than 4000 bytes), but when large fields, always report streams type cannot be used in batches. Online, Chinese, abroad, what Hibernate 56,73 documentation. It includes a wide range of search in this forum. Finally, two ways, in the configuration file, indicate that hibernate.jdbc.batch_size is 0; or hibernate.jdbc.use_streams_for_binary is true. Settings when setting for hibernate.jdbc.use_streams_for_binary settings, set it in the JVM environment. The result does not appear Streams Type Cannot Be Used In Batching error, but reports a Flush error. It can be said that my storage is simple. After Extends ImmutableType. Moreover, for all CLOB fields, a String type mapping database is used in the BO object a session.save (Object); if you have saved a lot of code). Online discovery, use the following ways to feasible Java code:
Session s = sf.openSession (); tx = s.begintransaction (); foo = new foo (); foo.setclob ("); s.save (foo); s.flush (); S.Refresh (foo, lockmode.upgrade); // grabs an oracle clob oracle.sql.clob clob = (oracle.sql.clob) foo.getClob (); java.io.writer PW = Clob.getChacterOutputStream (); PW.WRITE (); pw.close (); tx.commit (); s.Close ();
But this way, BO must indicate the clob attribute, and in general, each operation seems to be a separate code, some cost. I don't know, this problem, who is well solved, can be described in detail. Remarks Environment: DB: Oralce9i DBDriver: Oracle.jdbc.sql.OracleDriver Hibernate: Hibernate2.1.2 App: JBoss Test Phase, No Connection Pool Insert
Java code:
Bo.SetContentClob ("); session.save (bo); session.flush (); session.refresh (bo, lockmode.Upgrade); // grabs an oracle clob oracle.sql.clob clob = (ORACLE.SQL.CLOB) BO.GETCONTENTCLOB (); java.io.writer PW = Clob.getCharacterOutputStream (); PW.Write (Content); PW.Flush (); PW.Close (); session.flush () ;
Update
Java code:
Bo.SetContentClob (Hibernate.createclob (")); session.Update (bo); session.flush (); session.refresh (bo, lockmode.upgrade); // grabs an oracle clob oracle.sql.clob Clob = (ORACLE.SQL.CLOB) BO.GETCONTENTCLOB (); // Note: If you use WebLogic Connection Pool, use WebLogic OracleThinClob java.io.writer Pw = Clob.GetCharacterOutputStream (); PW.Write (Content); PW .flush (); pw.close (); session.flush (); this way is temporarily done, but for less flexible, cumbersome. Almost different DAOs need to be rewritten. Consider how to better solve ··· Reflections ...