-->
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 with hibernate query
PostPosted: Wed Feb 16, 2005 5:42 am 
Newbie

Joined: Wed Feb 16, 2005 5:32 am
Posts: 2
I have created the following classes and mapped them with hibernate:

----------------------
Class Customer
- int customerId
- Set departments
----------------------
Class Department
- int departmentId
- Set operators
----------------------
Class Operator(extends user)
- int userId
- Set departments
----------------------


A customer can have many departments.
An department can have many operators.
An operator can belong to many departments.

I use hibernate with a mySql database.
The database does not support subqueries/subselects.

I want to make a HQL query that gets me customers by operatorId.

I have the method:
"searchCustomerByOperatorId(long operatorId)"

Which should:
Find all the customers that has an Operator with userId(operatorId) in any of its departments.

Is there anybody who can help me creating this query?

/Casualty


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 16, 2005 7:30 am 
Newbie

Joined: Wed Feb 16, 2005 5:32 am
Posts: 2
I found this solution:

SELECT customer FROM Customer customer, Department department, Operator operator WHERE operator.userId="+operatorId+" AND operator = any elements(department.operators) and department = any elements(customer.departments)


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.