Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Criteria hibernate compare clob database field with String variable

 
Roberto pr
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

i have this Criteria Query with a description field in OffertaClass of type Clob and a Variable String desc
i have to use a eq or like

Criteria c = session.createCriteria(Offerta.class);

c.add(desc == null ? Restrictions.eq("desc", "desc"): Restrictions.eq("descrizione", Restrictions.in("desc",new org.hibernate.lob.ClobImpl[]{new org.hibernate.lob.ClobImpl(desc)})));

or

c.add(desc == null ? Restrictions.eq("desc", "desc"): Restrictions.like("descrizione", Restrictions.in("desc",new org.hibernate.lob.ClobImpl[]{new org.hibernate.lob.ClobImpl(desc)})));

but i get :

java.lang.ClassCastException: org.hibernate.criterion.InExpression cannot be cast to java.sql.Clob
at org.hibernate.type.ClobType.set(ClobType.java:50)
at org.hibernate.type.ClobType.nullSafeSet(ClobType.java:123)
at org.hibernate.loader.Loader.bindPositionalParameters(Loader.java:1707)
at org.hibernate.loader.Loader.bindParameterValues(Loader.java:1678)
at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1563)
at org.hibernate.loader.Loader.doQuery(Loader.java:673)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)
at org.hibernate.loader.Loader.doList(Loader.java:2220)
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)


how i can compare a clob field descizione with a String variable desc?

thank you!

Roby
 
Anantha Sharma
Ranch Hand
Posts: 43
Android Hibernate jQuery
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Roberto pr wrote:
Criteria c = session.createCriteria(Offerta.class);

c.add(desc == null ? Restrictions.eq("desc", "desc"): Restrictions.eq("descrizione", Restrictions.in("desc",new org.hibernate.lob.ClobImpl[]{new org.hibernate.lob.ClobImpl(desc)})));




your trouble lies here..


the system is trying to add a restriction in the Restrictions.eq("descrizione",); method.. where an object is expected (thats why the compiler is not complaining).


the remedy lies in a simple rewrite of the criteria restriction...

hope this helps.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic