-->
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.  [ 10 posts ] 
Author Message
 Post subject: HIBERNATE:clob field bug!!!! (oracle 10g )
PostPosted: Thu Sep 07, 2006 6:12 am 
Newbie

Joined: Mon May 10, 2004 9:14 pm
Posts: 12
i use hibernate to insert string to a clob column,when string length between 1000~2000 there is some errors,the string can't be inserted in to the database , but i use jdbc+c3p0(not use hibernate) every thing is ok. so i am sure this is hibernate's bug.any body can help me !!!!!!!!!!!!!!!!!!!!!!!!!!
there is the orace example :http://www.oracle.com/technology/sample_code/tech/java/codesnippet/jdbc/clob10g/ClobManipulationIn10g.java.html

Hibernate version:
version:3.1.3 and 3.2.*
Mapping documents:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="org.trundle.cms.po">
<class name="Clob" table="clob_tab" lazy="false">
<id column="id" length="32" name="id" type="string">
<generator class="uuid.hex"/>
</id>

<!--in database i use Clob type not varchar-->
<property name="clob" column="clob_col" type="string" />


</class>
</hibernate-mapping>

Code between sessionFactory.openSession() and session.close():
Code:
        org.hibernate.Session session = org.trundle.cms.db.HibernateUtil.getNewSession();
        org.hibernate.Transaction t = session.beginTransaction();
        org.trundle.cms.po.Clob po = new org.trundle.cms.po.Clob();
        po.setClob(MyExample.readFile());[b][color=blue]//file length is 1115 byte[/color][/b]
        session.save(po);
        session.flush();
        t.commit();
        session.close();

Full stack trace of any exception that occurs:
Code:
org.hibernate.exception.GenericJDBCException: Could not execute JDBC batch update

   at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:103)

   at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:91)

   at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)

   at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:202)

   at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:235)

   at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:139)

   at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:297)

   at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)

   at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:985)

   at org.trundle.test.ClobManipulationIn10g.main(ClobManipulationIn10g.java:228)

[color=red]Caused by: java.sql.BatchUpdateException: ORA-01461: can bind a LONG value only for insert into a LONG column[/color]


   at oracle.jdbc.driver.DatabaseError.throwBatchUpdateException(DatabaseError.java:343)

   at oracle.jdbc.driver.OraclePreparedStatement.executeBatch(OraclePreparedStatement.java:10698)

   at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeBatch(NewProxyPreparedStatement.java:1723)

   at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:58)

   at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:195)

   ... 6 more

Name and version of the database you are using:
oracle10g use release2 ojdbc4.jar
The generated SQL (show_sql=true):
Hibernate: insert into clob_tab (clob_col, id) values (?, ?)

Debug level Hibernate log excerpt:
info


Last edited by jjw on Thu Sep 07, 2006 6:20 am, edited 1 time in total.

Top
 Profile  
 
 Post subject: jdbc test code
PostPosted: Thu Sep 07, 2006 6:16 am 
Newbie

Joined: Mon May 10, 2004 9:14 pm
Posts: 12
below code run ok
Code:
    public void insertClob() throws SQLException {
            // Create a PreparedStatement object.
        PreparedStatement pstmt = null;
        try {
            // Create the database connection, if it is closed.
            if ((conn == null) || conn.isClosed()) {
                // Connect to the database.
                 //conn = DriverManager.getConnection(this.url, this.props);
                 conn = org.trundle.cms.db.HibernateUtil.currentSession().connection();
            }
            // Create SQL query to insert data into the CLOB column in the database.
            String sql = "INSERT INTO clob_tab(ID,CLOB_COL) VALUES(?,?)";
            // Read a big file(larger than 32765 bytes)
            String str = this.readFile();
            // Create the OraclePreparedStatement object
            pstmt = conn.prepareStatement(sql);
            // Use the same setString() method which is enhanced to insert
            // the CLOB data. The string data is automatically transformed into a
            // clob and inserted into the database column. Make sure that the
            // Connection property - 'SetBigStringTryClob' is set to true for
            // the insert to happen.
            pstmt.setString(1,System.currentTimeMillis()+"");
             pstmt.setString(2,str);
            // Execute the PreparedStatement
            conn.setAutoCommit(true);
            pstmt.execute();
           
        } catch (SQLException sqlex) {
            sqlex.printStackTrace();
            // Catch Exceptions and display messages accordingly.
            System.out.println("SQLException while connecting and inserting into " + "the database table: " + sqlex.toString());
        } catch (Exception ex) {System.out.println("Exception while connecting and inserting into the" + " database table: " +
                ex.toString());
        } finally { // Close the Statement and the connection objects.
            if (pstmt != null) {
                pstmt.close();
            }
            if (conn != null) {
                conn.close();
            }
        }
    }


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 07, 2006 8:26 pm 
Newbie

Joined: Mon May 10, 2004 9:14 pm
Posts: 12
Caused by: java.sql.BatchUpdateException: ORA-01461: can bind a LONG value only for insert into a LONG column


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 08, 2006 2:57 am 
Newbie

Joined: Mon May 10, 2004 9:14 pm
Posts: 12
the question is solved;
this is oracle release2 ojdbc.jar's bug


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 08, 2006 3:01 am 
Newbie

Joined: Mon May 10, 2004 9:14 pm
Posts: 12
oracle's example(operate clob from jdbc just like varchar2) is unilateral.it change a little thing , the example will not passed.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 20, 2006 12:40 am 
Newbie

Joined: Wed Dec 20, 2006 12:33 am
Posts: 1
Thank for you info! really answered my questions!!


Top
 Profile  
 
 Post subject: What did you upgrade the driver to?
PostPosted: Thu Feb 19, 2009 12:28 am 
Newbie

Joined: Thu Feb 19, 2009 12:25 am
Posts: 1
jjw wrote:
the question is solved;
this is oracle release2 ojdbc.jar's bug


I believe, I see the same problem, and I am wondering what version whould I upgrade the ojdbc driver to for 10 g oralce database,


Top
 Profile  
 
 Post subject: Re: HIBERNATE:clob field bug!!!! (oracle 10g )
PostPosted: Thu Nov 12, 2009 6:07 pm 
Newbie

Joined: Thu Jun 04, 2009 6:28 pm
Posts: 2
so whats the exact solution to this issue.
I have a table with clob fields and I am seeing intermittent update issues with the rows.
anyhelp is greatly appreciated.


Top
 Profile  
 
 Post subject: Re: HIBERNATE:clob field bug!!!! (oracle 10g )
PostPosted: Fri Oct 29, 2010 1:44 pm 
Newbie

Joined: Thu Oct 28, 2010 2:27 pm
Posts: 2
We encountered this error message as well, about the LONG datatype in a LONG column. The table definition didn't include a LONG typed column. For us, we use Java JPA & Hibernate Annotations to decorate our Entity Beans rather than the HBM config file. Also this issue was occurring in a VARCHAR2 typed column instead of a CLOB. The problem was solved when we added the "columnDefinition" attribute to the @Column annotation. The value for the attribute we set to "varchar2":

@Column(name="...", length=2048, columnDefinition="varchar2")

This fixed the problem right away. We have been using the ojdbc6.jar Oracle driver.

~dan


Top
 Profile  
 
 Post subject: Re: HIBERNATE:clob field bug!!!! (oracle 10g )
PostPosted: Fri Nov 05, 2010 5:31 am 
Newbie

Joined: Fri Nov 05, 2010 5:29 am
Posts: 1
In my case I was simply trying to insert string with 9000+ chars in varchar2 column with max. 4000 chars.
Simple validation resolved this error.


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

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.