-->
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.  [ 3 posts ] 
Author Message
 Post subject: Some help please with a specific query
PostPosted: Wed Mar 31, 2004 4:53 pm 
Newbie

Joined: Sun Oct 26, 2003 4:46 pm
Posts: 16
Location: Tallinn, Estonia
Hello,

I have the following mapping:

Code:
<hibernate-mapping>
  <class name="Project" table="projects">
    <id name="id" unsaved-value="0">
      <generator class="identity"/>
    </id>
    <property name="name"/>
    <property name="comments"/>
    <property name="startDate" type="date"/>
    <property name="endDate" type="date"/>
    <list name="activities" table="activities" cascade="all">
      <key column="project_id"/>
      <index column="position"/>
      <composite-element class="ProjectActivity">
        <property name="description"/>
        <property name="timestamp" column="time_stamp"/>
      </composite-element>
    </list>
  </class>
</hibernate-mapping>


In other words there are Projects which can have several ProjectActivities in a list.

Now I need to display a list of all activities across all projects together with the name of the project, sorted by the activity timestamp.

I can do this quite easily in SQL:

Code:
SELECT a.time_stamp, a.description, p.name
FROM activities a, project p
WHERE a.project_id = p.id
ORDER BY t.time_stamp


How do I specify in HQL that I want to sort based on the timestamp property of the elements of the activities property? And a similar question as to how to select the description property from that list?

_________________
best regards,
erik


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 31, 2004 6:55 pm 
Newbie

Joined: Mon Feb 09, 2004 1:40 am
Posts: 13
Location: Moscow, Russia
It may be smth. like that:
Code:
select a.timestamp, a.description, p.name
  from Project p
  inner join p.activities a
  order by a.timestamp

_________________
God is Real, unless declared as Integer.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 01, 2004 12:08 am 
Newbie

Joined: Sun Oct 26, 2003 4:46 pm
Posts: 16
Location: Tallinn, Estonia
Thank you, dimitry

This is exactly what I needed. This inner join with the list was something I couldn't figure out myself.

_________________
best regards,
erik


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