-->
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.  [ 1 post ] 
Author Message
 Post subject: Grouping an joining
PostPosted: Mon May 19, 2008 8:30 am 
Newbie

Joined: Mon May 19, 2008 7:45 am
Posts: 4
Hi,

I have the following situation.
I have an entity Employee that consists of the attributes

-id (Primary key)
-loginname
-version
-email
-givenName
-lastName
-organizationalUnit

loginname and version are the natural identifier.

Everytime a user logs on to the application a LDAP query checks if the attributes are still correct. If one of the attibutes email, givenName,
lastName, organizationalUnit has changed the Employee will be versioned.

Now my problem:
I want to create a HQL query that gives me a collection of all Employees with their last version.
This is my SQL query that returns the IDs of the Employee objects:

Code:
SELECT
    e2.id
FROM
   (SELECT loginname, max(version) AS version
    FROM Employee
    GROUP BY loginname) e1
   
    INNER JOIN
   
   (SELECT loginname, version, id
    FROM Employee) e2 ON e1.loginname= e2.loginname AND e1.version= e2.version


Now I want to use these IDs in an IN-clause of an HQL query that returns a list of objects of type Employee.

The base HQL query for the Employee list looks like:
Code:
FROM Employee e WHERE e.id IN (...)


Finally I have to merge the first query into the IN-condition of the second query. That's what's not working for me.

Any ideas?

Thank you in advance,
Thilo


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

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.