-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Help, problem using 'distinct' to query a list
PostPosted: Sat Sep 03, 2005 11:49 pm 
Newbie

Joined: Sat Sep 03, 2005 11:40 pm
Posts: 1
Location: La Jolla, CA
Hi,

I am using hibernate 3.0.

I'm trying to get a list of universities from my site table. My current approach is to write a select distinct query in Hibernate, for the siteParentName attribute; then use that list's size() method to get the number of elements.

I am getting a null pointer exception when instantiating the query:

public int getNumberUniversitites() {

Query query = null;
List list = null;

try {
query = session.createQuery("select distinct site.siteParentName from Site");
} catch (HibernateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

try {
list = query.list();
} catch (HibernateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return list.size();

}

thanks,
Jana


Top
 Profile  
 
 Post subject:
PostPosted: Sun Sep 04, 2005 1:37 am 
Pro
Pro

Joined: Fri Sep 02, 2005 4:21 am
Posts: 206
Location: Vienna
Hi,

You wrote
Code:
query = session.createQuery("select distinct site.siteParentName from Site");
.

Is that really the code you are using? I would expect
Code:
query = session.createQuery("select distinct site.siteParentName from Site site");


With a code equivalent to yours I get a QuerySyntaxError...

Erik


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.