-->
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.  [ 6 posts ] 
Author Message
 Post subject: Why DISTINCT doesnt't work
PostPosted: Mon Feb 21, 2005 11:49 am 
Newbie

Joined: Tue Feb 01, 2005 10:20 pm
Posts: 10
Hibernate version: 2.x

Hi,

I have this statement:
"select distinct s.currentstatus from Service s where service_id > 1"

which is very simple bu doesnt' work.
If anybody can give me an example of how to use DISTINCT with
Hibernate that will very appreciated.

Examples from the "Hibernate in Action" and from Hibernate documentation dont' work. I tried all of them.

Thanks,


Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:
net.sf.hibernate.QueryException: could not resolve property: currentstatus of: cas.system.app.model.Service [select distinct s.currentstatus from cas.system.app.model.Service s where service_id > 1]

at net.sf.hibernate.persister.AbstractPropertyMapping.toType(AbstractPropertyMapping.java:38)

at net.sf.hibernate.hql.PathExpressionParser.getPropertyType(PathExpressionParser.java:249)

at net.sf.hibernate.hql.PathExpressionParser.token(PathExpressionParser.java:123)

at net.sf.hibernate.hql.SelectPathExpressionParser.end(SelectPathExpressionParser.java:12)

at net.sf.hibernate.hql.ParserHelper.parse(ParserHelper.java:30)

at net.sf.hibernate.hql.SelectParser.token(SelectParser.java:170)

at net.sf.hibernate.hql.ClauseParser.token(ClauseParser.java:87)

at net.sf.hibernate.hql.ClauseParser.end(ClauseParser.java:114)

at net.sf.hibernate.hql.PreprocessingParser.end(PreprocessingParser.java:143)

at net.sf.hibernate.hql.ParserHelper.parse(ParserHelper.java:30)

at net.sf.hibernate.hql.QueryTranslator.compile(QueryTranslator.java:149)

at net.sf.hibernate.hql.QueryTranslator.compile(QueryTranslator.java:138)

at net.sf.hibernate.impl.SessionFactoryImpl.getQuery(SessionFactoryImpl.java:293)

at net.sf.hibernate.impl.SessionImpl.getQueries(SessionImpl.java:1561)

at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1532)

at net.sf.hibernate.impl.QueryImpl.list(QueryImpl.java:39)



Name and version of the database you are using: MySql 4.1


Top
 Profile  
 
 Post subject: Re: Why DISTINCT doesnt't work
PostPosted: Mon Feb 21, 2005 12:55 pm 
Regular
Regular

Joined: Thu Dec 18, 2003 2:14 am
Posts: 103
Location: Brooklyn, NY
tr wrote:
Examples from the "Hibernate in Action" and from Hibernate documentation don't work. I tried all of them.

It is hard to believe all of the examples for distinct are wrong in the edited, corrected, tested, and published book by the Hibernate developers.

It is far more likely to be a problem in your setup (mappings,etc.). However, "don't work" is a very vague term, and you didn't post your mappings and code as the form requires. Please post these, and what EXACTLY goes wrong (again, as directed in the posting guidelines).


Top
 Profile  
 
 Post subject: Re: Why DISTINCT doesnt't work
PostPosted: Mon Feb 21, 2005 12:59 pm 
Regular
Regular

Joined: Thu Dec 18, 2003 2:14 am
Posts: 103
Location: Brooklyn, NY
tr wrote:

Full stack trace of any exception that occurs:
net.sf.hibernate.QueryException: could not resolve property: currentstatus of: cas.system.app.model.Service [select distinct s.currentstatus from cas.system.app.model.Service s where service_id > 1]

at net.sf.hibernate.persister.AbstractPropertyMapping.toType(AbstractPropertyMapping.java:38)

at net.sf.hibernate.hql.PathExpressionParser.getPropertyType(PathExpressionParser.java:249)

at net.sf.hibernate.hql.PathExpressionParser.token(PathExpressionParser.java:123)

at net.sf.hibernate.hql.SelectPathExpressionParser.end(SelectPathExpressionParser.java:12)

at net.sf.hibernate.hql.ParserHelper.parse(ParserHelper.java:30)

at net.sf.hibernate.hql.SelectParser.token(SelectParser.java:170)

at net.sf.hibernate.hql.ClauseParser.token(ClauseParser.java:87)

at net.sf.hibernate.hql.ClauseParser.end(ClauseParser.java:114)

at net.sf.hibernate.hql.PreprocessingParser.end(PreprocessingParser.java:143)

at net.sf.hibernate.hql.ParserHelper.parse(ParserHelper.java:30)

at net.sf.hibernate.hql.QueryTranslator.compile(QueryTranslator.java:149)

at net.sf.hibernate.hql.QueryTranslator.compile(QueryTranslator.java:138)

at net.sf.hibernate.impl.SessionFactoryImpl.getQuery(SessionFactoryImpl.java:293)

at net.sf.hibernate.impl.SessionImpl.getQueries(SessionImpl.java:1561)

at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1532)

at net.sf.hibernate.impl.QueryImpl.list(QueryImpl.java:39)



Ah, I see the stack trace is there. Looks like a mapping problem with the currentstatus property.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 21, 2005 1:03 pm 
Newbie

Joined: Tue Feb 01, 2005 10:20 pm
Posts: 10
Hi,

This is a mapping I have:

<class name="Service" lazy="true" table="Service" discriminator-value="SERVICE">
<id name="id" column="service_id" type="long" unsaved-value="null">
<generator class="identity"/>
</id>
<discriminator column="SERVICE_TYPE" type="string"/>
-----
-----

<subclass name="cas.system.app.model.Equipment" lazy="true" discriminator-value="EQUIPMENT">
<property name="currentstatus" column="equipment_currentstatus" type="string"/>
------
------
</subclass>
</class>

All I need to do is to get distinct values from the "equipment_currentstatus" column.

Thank you,


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 21, 2005 1:21 pm 
Regular
Regular

Joined: Thu Dec 18, 2003 2:14 am
Posts: 103
Location: Brooklyn, NY
tr wrote:
<class name="Service" lazy="true" table="Service" discriminator-value="SERVICE">
<id name="id" column="service_id" type="long" unsaved-value="null">
<generator class="identity"/>
</id>
<discriminator column="SERVICE_TYPE" type="string"/>
-----
-----

<subclass name="cas.system.app.model.Equipment" lazy="true" discriminator-value="EQUIPMENT">
<property name="currentstatus" column="equipment_currentstatus" type="string"/>
------
------
</subclass>
</class>


Well, your HQL query is calling service.currentstatus:
"select distinct s.currentstatus from Service s where service_id > 1"
whereas it is actually mapped to the subclass Equipment


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 21, 2005 1:27 pm 
Newbie

Joined: Tue Feb 01, 2005 10:20 pm
Posts: 10
[/quote]

Well, your HQL query is calling service.currentstatus:
"select distinct s.currentstatus from Service s where service_id > 1"
whereas it is actually mapped to the subclass Equipment[/quote]

Thanks a lot for help. It does work now.
I tried so many examples that I lost control over the statement syntax.

Thanks again.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 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.