aspose file tools*
The moose likes Object Relational Mapping and the fly likes distinct in select query Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "distinct in select query" Watch "distinct in select query" New topic
Author

distinct in select query

srija patel
Greenhorn

Joined: Nov 14, 2008
Posts: 11
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

Joined: Nov 14, 2008
Posts: 11
Sorry, I forgot to mention that the 2 tables I'm joining are not related.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61043
    
  66

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Craig Taylor
Ranch Hand

Joined: Jul 17, 2008
Posts: 64
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

Joined: Nov 14, 2008
Posts: 11
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

Joined: Nov 14, 2008
Posts: 11
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

Joined: Sep 28, 2008
Posts: 3
in the result ,you can use HashSet to filter .

liket this :

HashSet hs=new HashSet(List)


Just want to make friends to improve my English,would you like to make friends with me?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: distinct in select query