-->
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.  [ 5 posts ] 
Author Message
 Post subject: Use DISTINCT with a subclass
PostPosted: Sat Feb 12, 2005 3:03 pm 
Newbie

Joined: Tue Feb 01, 2005 10:20 pm
Posts: 10
Hibernate version: 2.0

Name and version of the database you are using: MySql

Hi,

I try to get unique values from the subclass using DISTINCT but
nothing seems to work. Below is the one example I tried to execute but
it didn't work either.

Any help on this topic will be appreciated.

Thanks,

<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>

The generated SQL (show_sql=true):
List list = session.createSQLQuery("select{s}.EQUIPMENT_CURRENTSTATUS as {e.currentstatus} from service {s}
where SERVICE_TYPE = 'EQUIPMENT'", "e", Service.class).list();


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 14, 2005 6:44 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
there is no distinct keyword in what you show us

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 14, 2005 10:41 am 
Newbie

Joined: Tue Feb 01, 2005 10:20 pm
Posts: 10
emmanuel wrote:
there is no distinct keyword in what you show us


Sorry, I forgot to put DISTINCT in the statement.
It looks like this:

List list = session.createSQLQuery("select distinct{s}.EQUIPMENT_CURRENTSTATUS as {e.currentstatus} from service {s}
where SERVICE_TYPE = 'EQUIPMENT'", "e", Service.class).list();

I've also used examples from the "HIBERNATE IN ACTION" book but they don't work either.

Thank you for help.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 14, 2005 10:50 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Please read the docs, that query is totaly wrong. For example you are using an alias s you have never defined. Also, unless you use the currently quite undocumented H3 api, createSqlQueries can only return mapped entities.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 14, 2005 10:56 am 
Newbie

Joined: Tue Feb 01, 2005 10:20 pm
Posts: 10
michael wrote:
Please read the docs, that query is totaly wrong. For example you are using an alias s you have never defined. Also, unless you use the currently quite undocumented H3 api, createSqlQueries can only return mapped entities.


Thank you for reply.

As I've said before I've used different kind of queries.
Could you please show me what would be an example of correct syntax
for retrieving unique values from current_status column from the subclass(plsease see example below).

<class name="class1" .......

<subclass name="class2" .......
<property name="status" column="current_status" .......
</subclass>

</class>


Thank you,


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