• 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

distinct in select query

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm new to hibernate and want to execute something like

select distinct T.aaa as myvalue, T.bbb as mylabel from TABLE1 T, TABLE2 n where name = " + pname+ " and n.skey= t.skey and n.skey = " + pkey;

Using named query, I cud execute only this part;
from TABLE1 T, TABLE2 n where name = " + pname+ " and n.skey= t.skey and n.skey = " + pkey;

How do I select distinct through named query ??? Please reply back.
 
srija patel
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry, I forgot to mention that the 2 tables I'm joining are not related.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please take the time to choose the correct forum for your posts. This forum is for questions on Servlets.

For more information, please read this.

This post has been moved to a more appropriate forum.
 
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try using a group by instead of distinct :



should be :



Also, if you're doing hibernate be sure to lookup the Criteria() class and examples on how it's used.
 
srija patel
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I did as you said.
The query is like this

select flutime0_.TIMEUID as TIMEUID3_0_, flunav1x1_.DATASOURCEKEY as DATASOUR1_2_1_, flutime0_.SEASONKEY as SEASONKEY3_0_, flutime0_.MENUTEXT as MENUTEXT3_0_, flutime0_.FLUWK as FLUWK3_0_, flunav1x1_.SEASONKEY as SEASONKEY2_1_, flunav1x1_.SEASON as SEASON2_1_, flunav1x1_.GEOVALUE as GEOVALUE2_1_, flunav1x1_.GEOLABEL as GEOLABEL2_1_, flunav1x1_.GEOMASK as GEOMASK2_1_, flunav1x1_.WEEKS as WEEKS2_1_ from FLUTIME flutime0_, FLUNAV1 flunav1x1_ where flunav1x1_.GEOMASK=? and flunav1x1_.SEASONKEY=flutime0_.SEASONKEY and flunav1x1_.SEASONKEY=? and bitand(weeks, power(2, flutime0_.FLUWK))=power(2, flutime0_.FLUWK) group by flutime0_.FLUWK , flutime0_.MENUTEXT

I get following exception...
Exception in thread "main" org.hibernate.exception.SQLGrammarException: could not execute query
 
srija patel
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I saw Criteria API, but dont understand how to write the condition n.skey= t.skey of my query in the Join.
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
in the result ,you can use HashSet to filter .

liket this :

HashSet hs=new HashSet(List)
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic