-->
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: Fetching joined properties in native SQL query?
PostPosted: Thu Sep 01, 2005 4:39 am 
Newbie

Joined: Thu Sep 01, 2005 4:34 am
Posts: 1
Hello,

I have two tables - TEAMS and PLAYERS. PLAYERS have foreign key referencing TEAMS.

These tables are mapped to entities:

Code:
class Team
{
  Long    id;
  String  name;
  Integer gamesWon;
  ...
}

class Player
{
  Long   id;
  String name;
  String surname;
  ...
  Team   team;
}


When I want to fetch all the players along with their teams, I use the following HQL query:

Code:
from PLAYERS as p left outer join fetch p.team


But now, I want to do the same using native SQL, in order to inject some Oracle optimizer hints.

How to do this? The properties of "Player" are fetched OK, but "Team" are left empty.

This is my best try:

Code:
String sql = "select {p.*} from Players p, Teams t where t.id = p.team_id";
List players = session.createSQLQuery(sql, String[]{"p", "t"},
   Class[]{Player.class, Team.class}).list();




Thanks for any help!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 01, 2005 5:18 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
use named queries and their load-collection etc. support

_________________
Max
Don't forget to rate


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.