• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Criteria hibernate compare clob database field with String variable

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 43
Android Hibernate jQuery
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic