public void addGraph(Graph graph, String graph_body) throws
      HibernateException, SQLException {
    beginTransaction();
    graph.setGraph_content(Hibernate.createClob(" "));
    session.save(graph);
    session.flush();
    session.refresh(graph, LockMode.UPGRADE);
    oracle.sql.CLOB clobs = (oracle.sql.CLOB) graph.getGraph_content();
    java.io.Writer pw = clobs.getCharacterOutputStream();
    try {
      pw.write(graph_body);
      pw.flush();
      pw.close();
    }
    catch (IOException e) {
      throw new HibernateException(e);
    }
    endTransaction();
  }

解决方案 »

  1.   

    public void updateGraph(Graph graph, String graph_body) throws
          HibernateException, SQLException {
        try {
          beginTransaction();
          graph.setGraph_content(Hibernate.createClob(" "));
          session.update(graph);
          session.flush();
          if (null != graph_body) {
            session.refresh(graph, LockMode.UPGRADE);
            oracle.sql.CLOB clobs = (oracle.sql.CLOB) graph.getGraph_content();
            java.io.Writer pw = clobs.getCharacterOutputStream();
            pw.write(graph_body);
            pw.flush();
            pw.close();
          }
          endTransaction();
        }
        catch (IOException e) {
          throw new HibernateException(e);
        }
      }