-->
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.  [ 8 posts ] 
Author Message
 Post subject: Duplicate results in query
PostPosted: Thu Dec 11, 2003 12:46 pm 
Beginner
Beginner

Joined: Thu Oct 02, 2003 8:02 am
Posts: 45
I have 2 classes User and Event :

Code:
public class User
{
     private Set events; //monodirectionnal association
     //...
}

when i execute the following query

Code:
select elements(user.events) from Internaute as user inner join user.events as evt  where user.id="flam70" and evt.periode="2003-12-12"


results are duplicated.
What 's wrong with it ?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 11, 2003 12:54 pm 
Expert
Expert

Joined: Tue Sep 16, 2003 4:06 pm
Posts: 318
Location: St. Petersburg, Russia
Could you show what SQL it trnaslates into?

PS: I think you need something like "select distinct"


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 11, 2003 1:00 pm 
Beginner
Beginner

Joined: Thu Oct 02, 2003 8:02 am
Posts: 45
Here is the SQL SELECT
Be careful : evenement is event and internaute is user

Hibernate: select evenemen3_.identifiant as x0_0_ from internaute internau0_ lef
t outer join evenement evenemen1_ on internau0_.identifiant=evenemen1_.internaut
e_id, evenement evenemen2_, evenement evenemen3_ where internau0_.identifiant=ev
enemen2_.internaute_id and evenemen2_.identifiant=evenemen3_.identifiant and ((i
nternau0_.identifiant=? )and(evenemen1_.periode=? ))
Hibernate: select evenemen0_.identifiant as identifi1_0_, evenemen0_.type as typ
e0_, evenemen0_.periode as periode0_, evenemen0_.heure as heure0_, evenemen0_.ti
tre as titre0_, evenemen0_.description as descript6_0_, evenemen0_.remarque as r
emarque0_, evenemen0_.heureFin as heureFin0_, evenemen0_.observation as observat
9_0_, evenemen0_.lieu as lieu0_, evenemen0_.indication as indication0_ from even
ement evenemen0_ where evenemen0_.identifiant=?
Hibernate: select evenemen0_.identifiant as identifi1_0_, evenemen0_.type as typ
e0_, evenemen0_.periode as periode0_, evenemen0_.heure as heure0_, evenemen0_.ti
tre as titre0_, evenemen0_.description as descript6_0_, evenemen0_.remarque as r
emarque0_, evenemen0_.heureFin as heureFin0_, evenemen0_.observation as observat
9_0_, evenemen0_.lieu as lieu0_, evenemen0_.indication as indication0_ from even
ement evenemen0_ where evenemen0_.identifiant=?


and the result :
essai ,10:00
essai ,10:00
RDV M. DUPOND ,8:00
RDV M. DUPOND ,8:00


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 11, 2003 1:13 pm 
Expert
Expert

Joined: Tue Sep 16, 2003 4:06 pm
Posts: 318
Location: St. Petersburg, Russia
What are you trying to do?

It looks like you want to load ALL events of the specific user. Correct? In this case try to use "select distinct ...".

But your query looks very inefficient for this case.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 11, 2003 1:16 pm 
Expert
Expert

Joined: Tue Sep 16, 2003 4:06 pm
Posts: 318
Location: St. Petersburg, Russia
If you need to load only events with specific period,

Code:
select evt from Internaute as user inner join user.events as evt  where user.id="flam70" and evt.periode="2003-12-12"


will do the job.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 11, 2003 1:22 pm 
Beginner
Beginner

Joined: Thu Oct 02, 2003 8:02 am
Posts: 45
You are right. I want to load ALL events of the specific user that match a specific date

For example, all events of user flam70 for the day "2003-12-12".

You seem to say that it looks very inefficient. So is there a better way to do so.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 11, 2003 1:28 pm 
Beginner
Beginner

Joined: Thu Oct 02, 2003 8:02 am
Posts: 45
OK. Your query works well. THANKS


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 11, 2003 1:37 pm 
Expert
Expert

Joined: Tue Sep 16, 2003 4:06 pm
Posts: 318
Location: St. Petersburg, Russia
Look, "all events of the specific user that match a specific date" and "ALL events of specific user" are a bit different things :)


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