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

HQL -> Criteria....

 
jay vas
Ranch Hand
Posts: 407
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys : Im trying to express this HQL as a criteria statement and can't get it right.

Can somebody please help ?

Im confused because the field description is a String.
How can I make a criteria that returns an object that is not a mapped table-bean object ?
 
jay vas
Ranch Hand
Posts: 407
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry that HQL is incorrect, its actually
select distinct (r.description) from RefPmsusertag r
 
Anirudh Vyas
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My suggestion go through Criteria Documentation here : Hibernate Criteria Query

You create a criteria like this :

session.createCriteria(SomeClass.class,"ALIAS_").createAlias("ALIAS_.SOME_PROPERTY").setResultTransformer(Criteria.ALIAS_TO_ENTITY_MAP).list();
you iterate through the list like this



Regards
Vyas, Anirudh
 
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper
Posts: 4968
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe a full code snippet using the Criteria API will help. Here's a sample of getting a list of results:



To massage the results, you can start using Example or Restriction classes to help get the results you want. Here's an example:



I wrote a free tutorial on the subject of using the Criteria API with Hibernate. You might find it helpful:

How to Use the Criteria API with Hibernate - Simple Examples and Code Snippets

Good luck!

-Cameron McKenzie
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic