-->
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.  [ 3 posts ] 
Author Message
 Post subject: Exception when using query by Example with Oracle CLOB
PostPosted: Fri Jul 25, 2008 11:04 am 
Newbie

Joined: Wed Jun 20, 2007 3:38 am
Posts: 3
Hi,

I am trying to use query by example on a class with a clob field, but I get an 'SQlGrammarException: inconsistent datatypes: expected - got CLOB'
when I call criteria.uniqueResult();.

I attached a small Testcase and the received Exception below.

Hibernate version: 3.2.6

Mapping documents:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
    "-//Hibernate/Hibernate Configuration DTD//EN"
    "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
   
<hibernate-configuration>
    <!-- a SessionFactory instance listed as /jndi/name -->
    <session-factory>
       
        <property name="hibernate.connection.driver_class">oracle.jdbc.OracleDriver</property>
        <property name="hibernate.connection.url">jdbc:oracle:thin:@localhost:1521:XE</property>
        <property name="hibernate.connection.username">statistik</property>
        <property name="hibernate.connection.password">statistik</property>
        <property name="hibernate.connection.pool_size">1</property>
        <property name="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</property>
       
        <!-- Enable Hibernate's automatic session context management -->
        <property name="current_session_context_class">thread</property>
       
        <!-- Disable the second-level cache  -->
        <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
       
        <!-- Echo all executed SQL to stdout -->
        <property name="show_sql">true</property>
       
        <property name="hibernate.hbm2ddl.auto">create</property>
       
    </session-factory>
</hibernate-configuration>


Testcase:
Code:
public class Main {

   /**
    * @param args
    */
   public static void main(String[] args) {
      SessionFactory sessionFactory = new AnnotationConfiguration().addAnnotatedClass(DataBean.class).configure().buildSessionFactory();
      Session session = sessionFactory.getCurrentSession();
      DataBean dataBean = new DataBean();
      dataBean.setMyClob("D A T A");
      
      Transaction tx = session.beginTransaction();
      DataBean persBean = new DataBean();
      session.save(persBean);
      tx.commit();
      

      Example example = Example.create(dataBean).excludeNone().excludeProperty("id");
      session = sessionFactory.getCurrentSession();
      tx = session.beginTransaction();
      Criteria crit = session.createCriteria(DataBean.class);
      crit.add(example);
      Object res = crit.uniqueResult();
      System.out.println("Got Result: "+ res);
      tx.commit();

   }

}


Code:
@Entity
public class DataBean {
   
   @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "id", nullable = false)
   private Long id;

    @Column(name = "myclob")
    @Lob
   private String myClob;

   /**
    * @return
    */
   public Long getId() {
      return id;
   }

   /**
    * @param id
    */
   public void setId(Long id) {
      this.id = id;
   }

   /**
    * @return
    */
   public String getMyClob() {
      return myClob;
   }

   /**
    * @param myClob
    */
   public void setMyClob(String myClob) {
      this.myClob = myClob;
   }
}


Full stack trace of any exception that occurs:
WARNUNG: SQL Error: 932, SQLState: 42000
25.07.2008 16:24:47 org.hibernate.util.JDBCExceptionReporter logExceptions
SCHWERWIEGEND: ORA-00932: Inkonsistente Datentypen: - erwartet, CLOB erhalten

Exception in thread "main" org.hibernate.exception.SQLGrammarException: could not execute query
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.loader.Loader.doList(Loader.java:2216)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2104)
at org.hibernate.loader.Loader.list(Loader.java:2099)
at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:94)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1569)
at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:283)
at org.hibernate.impl.CriteriaImpl.uniqueResult(CriteriaImpl.java:305)
at test.Main.main(Main.java:51)
Caused by: java.sql.SQLException: ORA-00932: Inkonsistente Datentypen: - erwartet, CLOB erhalten

at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:331)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:288)
at oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:745)
at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:216)
at oracle.jdbc.driver.T4CPreparedStatement.executeForDescribe(T4CPreparedStatement.java:810)
at oracle.jdbc.driver.OracleStatement.executeMaybeDescribe(OracleStatement.java:1039)
at oracle.jdbc.driver.T4CPreparedStatement.executeMaybeDescribe(T4CPreparedStatement.java:850)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1134)
at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3339)
at oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatement.java:3384)
at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:186)
at org.hibernate.loader.Loader.getResultSet(Loader.java:1787)
at org.hibernate.loader.Loader.doQuery(Loader.java:674)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)
at org.hibernate.loader.Loader.doList(Loader.java:2213)
... 7 more


Name and version of the database you are using:
Oracle Database 10g Express Edition Release 10.2.0.1.0

The generated SQL (show_sql=true):
Hibernate: select hibernate_sequence.nextval from dual
Hibernate: insert into DataBean (myclob, id) values (?, ?)
Hibernate: select this_.id as id0_0_, this_.myclob as myclob0_0_ from DataBean this_ where (this_.myclob=?)

Debug level Hibernate log excerpt:


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 28, 2008 3:46 am 
Newbie

Joined: Wed Jun 20, 2007 3:38 am
Posts: 3
some more Information:

the Problem seems to be that Oracle does not support the '='-Operator for LOBs (see http://www.dbforums.com/showthread.php?t=994118 ).

But as you can see in the generated SQL statements, Hibernate tries to use the '='-Opterator for comparison, when it should use something like dbms_lob.INSTR() / dbms_lob.SUBSTR() or to_char().

Anyone know what I can do to solve this?

Thanks in advance.


Top
 Profile  
 
 Post subject: Better late than never...
PostPosted: Fri Sep 05, 2008 2:58 pm 
Newbie

Joined: Fri Sep 05, 2008 2:52 pm
Posts: 1
Location: St. Louis, MO
This is waaaay too late to do you any good, but perhaps this will help some poor sap in the future. ;) I ran into the same issue and fixed it by tossing a ".enableLike(MatchMode.EXACT)" call into my Example. So try changing:

Code:
Example example = Example.create(dataBean).excludeNone().excludeProperty("id");

to read:

Code:
Example example = Example.create(dataBean).excludeNone().excludeProperty("id").enableLike(MatchMode.EXACT);

I wonder, is this something that needs to be fixed in the Oracle dialect?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.