File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

distinct in select query

 
srija patel
Greenhorn
Posts: 11
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, I forgot to mention that the 2 tables I'm joining are not related.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64171
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
Craig Taylor
Ranch Hand
Posts: 64
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
Nathaniel Wang
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
in the result ,you can use HashSet to filter .

liket this :

HashSet hs=new HashSet(List)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic