11

I'm using Hibernate Tools 3.2.1.GA with Spring version 3.0.2. I'm tying to insert data into Oracle (10g) database field of type clob as follows.

Clob c=Hibernate.createClob(request.getParameter("someTextFieldValueOnJSPPage");
pojoObj.setSomeClobProperty(c);

it works just fine but when I attempt to insert a stream of data using a CKEditor, demo on my JSP page (the CKEditor simply renders an HTML <textarea></textarea> element) that may involve formatted text as well as images, flash etc, it throws the following exception.

org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.hibernate.exception.GenericJDBCException: could not update: [model.Cms#1]

org.hibernate.exception.GenericJDBCException: could not update: [model.Cms#1]

java.sql.SQLException: operation not allowed: streams type cannot be used in batching

How to resolve that exception? Is this the Oracle driver problem or something else? I'm using ojdbc14.jar, Oracle JDBC Driver version - 9.0.2.0.0.


UPDATE:

One of the entities that uses the Clob type is

public class Cms  implements java.io.Serializable
{
     private BigDecimal cmsId;
     private Clob aboutUs;     //I'm currently dealing with this property.
     private Clob contactUs;
     private Clob privacyPolicy;
     private Clob returnPolicy;
     private Clob shippingPolicy;
     private Clob termsOfUse;
     private Clob exchangeLinks;
     private Clob disclaimer;
     private Clob aboutProducts;
     private Clob purchasingConditions;
     private Clob faq;

    //Parameterized constructor(s) along with the default one as and when needed.

    //Getters and setters.
}

In my Spring controller class, I'm using the following code to perform insertion on the Clob type in Oracle.

Cms c=new Cms();
c.setCmsId(new BigDecimal(0));
c.setAboutUs(Hibernate.createClob(request.getParameter("txtAboutUs")));
session.save(c);
session.flush();
session.getTransaction().commit();
model.put("status", "1");
model.put("msg","Insertion done successfully.");
//setParameter(cb);

Where model is simply a Map model, a formal parameter of the submit() method in the Spring controller class which is invoked when a submit button is clicked on the JSP page.


I'm retrieving data using the following simple method in the Spring controller class

private void getData(Map model)
{
    Session session=NewHibernateUtil.getSessionFactory().getCurrentSession();
    session.beginTransaction();
    List<Cms>list=session.createQuery("from Cms order by cmsId desc").list();
    model.put("list", list);

    session.flush();
    session.getTransaction().commit();
}

Tried to do as mentioned here but to no avail (I'm facing the same exceptions as specified in that question).

Community
  • 1
  • 1
Tiny
  • 27,221
  • 105
  • 339
  • 599
  • It was indeed the Oracle driver problem. I was using `Oracle JDBC Driver version - 9.0.2.0.0`. I have just downloaded a new version from [here](http://www.oracle.com/technetwork/database/enterprise-edition/jdbc-10201-088211.html) which is `Oracle JDBC Driver version - 10.2.0.5.0` which works just fine in all the situations. – Tiny Aug 29 '12 at 20:17
  • 6
    You should post that as the answer and mark it. – pickypg Sep 04 '12 at 05:12
  • 4
    @Tiny Answer your own question and then mark it as an answer. Thank You. – Prakash K Sep 04 '12 at 07:07
  • Well, I think the first comment of mine is sufficient to answer this question and therefore, I don't feel like answering this question by myself. It looks like cheating to me. If someone has more details on this question and post it as an answer then I will consider marking it as an accepted answer with one upvote I can do. Thank you. – Tiny Oct 26 '12 at 22:24
  • @Tiny this question is in the top of unanswered question list and it's very distracting, I don't think that more details will ever be available - the first Oracle drivers had very buggy BLOB support - it was a story of strange exceptions, blobs filled with zeroes instead of data, and weird workarounds - and all that questions ended up when someone finally posted an answer that downloading the latest driver from oracle.com fixed the problem. I can't currently find that questions, so I think that copy-pasting your comment as an answer will be just fine. – Boris Treukhov Oct 27 '12 at 19:41
  • @Boris Treukhov - Done. It looks like cheating though. Thank you. – Tiny Oct 28 '12 at 03:52
  • @Tiny Why do you say it is cheating? You are not going to get any reputations by answering your own question, though if somebody else finds it useful he may upvote. And moreover if it is marked as an answer it would be readily available for those looking for a solution. Answer has more visibility than a comment. Thanks – Chaitanya Marathe Oct 30 '12 at 14:01
  • @Chaitanya Marathe - One cannot believe in my answers and yes regrading my age I would say one should indeed **not** believe in my answers. I'm even far from a beginner. I'm a self-learner and obviously, have no special experience like other people have. Thank you. – Tiny Nov 03 '12 at 18:06
  • 3
    @Tiny I m impressed by your honesty and your thought process. Keep up the good work. Age does not matter as long as you have the skill, that is the beauty of software development :-). By the way you seem to be much more mature then your age :-). – Chaitanya Marathe Nov 05 '12 at 12:11

1 Answers1

18

The exception being thrown as mentioned in the question was owing to the fact that the older version of the Oracle drivers might not seem to work with the Oracle clob datatype. I was using Oracle JDBC Driver version - 9.0.2.0.0. I downloaded a new version from here which is Oracle JDBC Driver version - 10.2.0.5.0 which works just fine for my application in all the situations.

Somewhere on the internet, it was stated by someone that if the data held by a CKEditor is converted (encoded) to base64 while inserting into the Oracle clob datatype, the approach is going to work without updating the driver (means with the older version of the Oracle drivers) (which is as obvious requires to decode from base64 while retrieving the data from the database).

but I indeed didn't put it into practice as the new version of the driver I downloaded is working fine for me. So, I'm not sure about the later approach and I'm leaving it to the readers.

Lion
  • 18,729
  • 22
  • 80
  • 110
Tiny
  • 27,221
  • 105
  • 339
  • 599