NHibernate's inner join gives the "Path expected to join"

I have three tables:

- Person
- User
- PersonSecret

where PersonSecret refers to the person and user:

<class name="PersonSecret" table="PersonSecret" lazy="false"  >
<id name="Id" column="Id" type="Guid">      
                <generator class="assigned"/>
</id>
...
<many-to-one  name="Person" class="Person" foreign-key="FK_Person_PersonSecret" lazy="proxy" fetch="select">
    <column name="PersonId"/>
</many-to-one>
<many-to-one  name="User" class="User" foreign-key="FK_User_PersonSecret" lazy="proxy" fetch="select">
    <column name="UserId"/>
</many-to-one>

This is a mapping from User to PersonSecret:

<set name="PersonSecrets" lazy="true" inverse="true" cascade="save-update" >
<key>
    <column name="UserId"/>
</key>
<one-to-many class="PersonSecret"/>

And this is from Person to PersonSecret:

<set name="PersonSecrets" lazy="true" inverse="true" cascade="save-update" >
<key>
    <column name="PersonId"/>
</key>
<one-to-many class="PersonSecret"/>

Now I am trying to select all persons who have an entry in PersonSecret for a specific user:

var query = this.Session.CreateQuery(@"from Person a inner join PersonSecret b 
          where b.UserId = :userId and b.RemindeBirthday = :remind");

Now this gives me an ExceptionMessage: "The path expected to connect"

Can someone help me what am I doing wrong? - Thank.

+5
source share
2 answers

There are several problems in your HQL query:

  • HQL , . PersonSecret.User.Id where UserId.
  • Person.PersonSecrets join, NHibernate , .
  • , with, where.

:

var query = this.Session.CreateQuery(
    @"from Person as a inner join a.PersonSecrets as b with b.User.Id = :userId and b.RemindeBirthday = :remind");

:

+3

"ON".

inner join PersonSecret b ON b.PersonId = a.PersonId
-1

All Articles