Hibernate version:
2
Name and version of the database you are using:
Oracle 9i
Let's say I have a pojo called Person, wich contains the fields name, age and id. I also have a pojo called Races, that contains the fields date, raceNumber racer (instance of Person) and id.
If a person has raced 3 times, my database will have in the race table 3 races, with their dates and raceNumber from 1 to 3 and the same racer.
Now, suppose I'd like to retrieve a racer from my database along with the date of his first race using the racer's name. So I created a pojo called Info which contains name, age and date.
So my query would end up lookin like this
Code:
String query = "select new com.mySystem.pojo.Info(
race.date,
person.name,
person.age
from
Race race,
Person person
where
race.raceNumber = 1
and race.racer.id = person.id
and race.name = supplied_name";
I now there might be errors in this query but it is only so you can understand what I am trying to do. Now the real problem is this:
What if the person has never raced before? I still want his info, but with a query like this I will get nothing, since the results depend on the existence of entries in the race table. How can I fix this?