-->
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: query does not return records with null values
PostPosted: Thu May 18, 2006 8:27 am 
Newbie

Joined: Fri Mar 31, 2006 8:49 am
Posts: 4
Location: NL
I'm having trouble with a table containing null values.
I have a Player table and object containing a column Playerclub_id as follows:

Code:
Player.hbm:
<many-to-one
   cascade="none"
   class="PlayerClub"
   column="playerclub_id"
   not-null="false"
   name="playerClub"
/>


Now I want to load a player using the following code:

Code:
Query query = session
   .createQuery("SELECT new Player(p.id, state, p.name, p.profileUrl, "
   + "p.photoUrl, p.type, p.playerClub, p.dateOfBirth) "
   + "FROM Player as p JOIN p.states as state "
   + "WHERE state.round.id = :roundId AND state.club.id = :clubId AND p.type.id = :typeId "
   + "ORDER BY  p.name ASC");

query.setInteger("roundId", roundId.intValue());
query.setInteger("clubId", clubId.intValue());
query.setInteger("typeId", playerTypeId.intValue());
query.setCacheable(true);
query.setCacheRegion(CACHE_NAME);
List results = query.list();


Problem is that for rows that have null values in playerClub_id, the corresponding Player objects are not in the result List. In other words, the query does not return these records.

What am I doing wrong?

Name and version of the database you are using: MySQL

Hibernate version: 2.x


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 18, 2006 8:56 am 
Regular
Regular

Joined: Wed Aug 25, 2004 6:23 am
Posts: 91
Referencing p.playerClub will create an implicit inner join. Try this instead:-

Code:
Query query = session
   .createQuery("SELECT new Player(p.id, state, p.name, p.profileUrl, "
   + "p.photoUrl, p.type, plClub, p.dateOfBirth) "
   + "FROM Player as p JOIN p.states as state "
   + "left outer join p.playerClub as plClub "
   + "WHERE state.round.id = :roundId AND state.club.id = :clubId AND p.type.id = :typeId "
   + "ORDER BY  p.name ASC");


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.