With some help from an old post in the Hibernate forum I found a solution:
public class DogMap : ClassMap<Dog> {
public DogMap() {
Table("Dogs");
Id(x => x.Id);
HasOne( x=> x.Owner)
.Fetch.Join();
}
}
public class OwnerMap : ClassMap<Owner> {
public OwnerMap() {
Table("Owners");
//owners share the same primary-key as dogs
Id(x => x.Id).GeneratedBy.Foreign("Dog");
//both sides should be mapped as HasOne
HasOne( x => x.Dog)
.Constrained()
.Fetch.Join();
}
}
And the working query is
var ownerlessDogs = session
.QueryOver<Dog>()
.Left.JoinAlias(x => x.Owner, () => owner)
//this is the trick, restrict on Id
.WhereRestrictionOn( x => x.Owner.Id ).IsNull
.List();