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: