-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Still having problem in handling oracle.CLOB
PostPosted: Mon Jan 03, 2005 10:58 pm 
Newbie

Joined: Thu Dec 16, 2004 2:58 am
Posts: 5
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!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.