-->
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: Join With question (possible bug)
PostPosted: Tue Aug 03, 2010 5:15 pm 
Newbie

Joined: Tue Aug 03, 2010 4:53 pm
Posts: 1
I've got a unidirectional OneToMany relationship that I'd like to do an outer join on. However, the query results aren't exactly correct unless I change the table structure a bit.

As an example lets use the entities Team and Player. On the team entity we'll include the following mapping to player:

@OneToMany()
public Set<Player> getPlayers() {
return players;
}
public void setPlayers(Set<Player> players) {
this.players = players
}

The current configuration should result in three tables: TEAM, TEAM_PLAYER, and PLAYER

Now lets say I want to run the following HQL query:
SELECT t.name, p.name
FROM Team t
LEFT OUTER JOIN t.players p WITH p.salary > 100000

The resultant SQL will be something like:
select t.name, p.name
from TEAM t
left outer join TEAM_PLAYER tp ON tp.TEAM_ID = t.ID
left outer join PLAYER p on tp.PLAYER_ID = p.ID and p.salary > 100000

This will perform a join to every player on the team regardless of what their salary is. This is because of the way it splits the single HQL outer join (t.players) into two SQL outer joins (TEAM_PLAYER and PLAYER).

There is a workaround to this problem by adding the @JOIN_COLUMN annotation so that a TEAM_ID column will be placed on the player table instead of creating the intermediary TEAM_PLAYER table. However, this solution causes the database to no longer be normalized. Keep in mind that this is just a simplified example to get my point across and that my real world example is far more complex. What do you think? Should I file a bug for this issue? Thanks for your help.


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.