• Post Reply Bookmark Topic Watch Topic
  • New Topic

Hibernate Query

 
Håkan Axheim
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Need to create a little more difficult query to my database with hibernate.
The sql statement looks like this:

select customerID,(case when col1=:searchCriteria then amount1 else 0 end + case when :searchCriteria='B' then amount2 else 0 end) from testTable where (:searchCriteria='A' or :searchCriteria='B')

In my Dao class I have tried to perform this query in this way.

Query query = (Query) session.createQuery(sqlStatement)
.setParameter("searchCriteria",searchCriteria);

Is this the right way to do this?

 
Dave Tolls
Ranch Hand
Posts: 2369
25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What happened when you tried it?

Testing it out is almost always going to be quicker than a forum post...
 
Happiness is not a goal ... it's a by-product of a life well lived - Eleanor Roosevelt. Tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!