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