Hibernate version:2.1.2
Mapping documents:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >
<hibernate-mapping package="src">
<class name="Info" table="INFO">
<id
column="INFO_ID"
name="Id"
type="integer"
>
<generator class="vm" />
</id>
<property
column="INFO_CONT"
name="InfoCont"
not-null="false"
type="src.StringClobType"
/>
<property
column="INFO_AREA"
length="100"
name="InfoArea"
not-null="false"
type="string"
/>
<property
column="INFO_DATE"
length="7"
name="InfoDate"
not-null="false"
type="date"
/>
</class>
</hibernate-mapping>
Full stack trace of any exception that occurs:
Caused by: java.io.IOException: No more data to read from socket
at oracle.jdbc.dbaccess.DBError.SQLToIOException(DBError.java:716)
at oracle.jdbc.driver.OracleClobWriter.flushBuffer(OracleClobWriter.java:270)
at oracle.jdbc.driver.OracleClobWriter.close(OracleClobWriter.java:232)
at src.StringClobType.nullSafeSet(StringClobType.java:113)
... 35 more
Name and version of the database you are using:oracle of 9.2.0.1
As following the given solutions(I'm really sorry for forgetting the topic and author!), I use UserType to define a class named StringClobType, and the code in nullSafeSet() method is:
Code:
public void nullSafeSet(PreparedStatement st, Object value, int index)
throws HibernateException, SQLException {
if (value == null) {
st.setNull(index, sqlTypes()[0]);
return;
}
try {
Connection conn = st.getConnection().getMetaData().getConnection();
log.info(conn.getClass().getName());
Writer tempClobWriter = null;
CLOB tempClob = CLOB.createTemporary(conn, true,
CLOB.DURATION_SESSION);
try {
tempClob.open(CLOB.MODE_READWRITE);
tempClobWriter = tempClob.getCharacterOutputStream();
tempClobWriter.write((String)value);
tempClobWriter.flush();
} finally {
if (tempClobWriter != null)
tempClobWriter.close();
tempClob.close();
LobCleanUpInterceptor.registerTempLobs(tempClob);
}
st.setClob(index, (Clob) tempClob);
} catch (IOException e) {
e.printStackTrace();
throw new HibernateException(e);
}
}
The code of main class named InfoManager(used the eclipse plugins of Hibernate Synchronizer) is
Code:
package src;
import oracle.jdbc.driver.OracleDriver;
import oracle.sql.*;
import net.sf.hibernate.*;
import javax.servlet.http.*;
import java.sql.PreparedStatement;
import java.util.*;
import java.sql.*;
import src.base.*;
import src.dao.*;
/**
* @author wangq
*
* TODO
*/
public class InfoManager {
public void addInfo(HttpServletRequest hsr)
throws HibernateException, NumberFormatException, SQLException{
// Get relative parameters from HttpServletRequest
int id = 1;
String infoArea = hsr.getParameter("infoArea");
String infoCont = hsr.getParameter("infoCont");
// Load the configuration file
_RootDAO.initialize();
//Session s = _RootDAO.
// Create a instance of Info represents a new info to be added
Info newInfo = new Info(new Integer(id));
newInfo.setInfoArea(infoArea);
newInfo.setInfoDate(Calendar.getInstance().getTime());
InfoDAO infoDao = new InfoDAO();
StringClobType oct = new StringClobType();
DriverManager.registerDriver(new OracleDriver());
Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@10.0.0.61:1521:zgxz", "swb", "swb");
oct.nullSafeSet(conn.prepareStatement("select * from info"), infoCont, 4);
newInfo.setInfoCont(oct);
infoDao.save(newInfo);
}
public List getAllInfos() throws Exception{
//Load the configuration file
_RootDAO.initialize();
// Create a instance of Info represents a new info to be added
//Info newInfo = new Info();
InfoDAO infoDao = new InfoDAO();
List all = infoDao.findAll();
return all;
}
}
When the above class is running, the exception occurs, and I find no suitable solution through internet.
'Thanks lot and lot for someone giving me a right suggestion!