-->
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: Is my HQL query correct ?
PostPosted: Fri Apr 23, 2004 5:42 pm 
Beginner
Beginner

Joined: Sun Mar 28, 2004 7:18 pm
Posts: 26
I have the following classes : PolicyDim, ClaimantSnapshotFact and DepartmentDim.

PolicyDim - ClaimantSnapshotFact = 1-M
ClaimanSnapshotFact - DepartmentDim - 1-1

I want all policies with a policy number of '123456' that have an effective date between x and y and belong to department name 'No Department'

Here is the data in the database :

- There are 3 policies with policy number '123456' with different effective dates dt1, dt2 and dt3
- Only 1 policy is tied to ClaimantSnapshotFacts (the others have no ClaimantSnapshotFacts)
- This 1 policy has 2 CliamantSnapshotFacts, and both these ClaimantSnapshotFacts have a department name of 'No Department'

So if I want all policies that have a policy number of '123456' that have effective dates between dt1 and dt3 and belong to a department called 'No Department', here is my HQL :

select policy
from com.accidentfund.common.db.hibernate.PolicyDim as policy
join policy.claimantSnapshotFacts as facts
where policy.policyNumber = ?
and policy.effectiveDate between ? and ?
and facts.departmentDim.departmentName = ?

I am supplying the right params to the ?

But I get back 2 policy (PolicyDim) objects, both of which are the same object. Shouldnt this query above return me just 1 ?

Should I be supplying the 'distinct' keyword here ? I dont think I need to, but if so, please explain why.

Unfortunately, hibernate does not print the SQL for me on the console despite my show_sql=true, so I cant see the query that is being run.

Please let me know why I get back duplicate copies of the same PolicyDim object.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Apr 24, 2004 9:54 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Quote:
This 1 policy has 2 CliamantSnapshotFacts


This is exactly why a join in SQL will produce 2 identical rows. You should really try getting the SQL logging to work. (there is a log4j logger too for sql logging). For your problem, use distinct.


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.