3
I am trying to run a JOIN using HQL with Nhibernate and returns an empty list. How to do this ?
I’m trying like this.
[Serializable]
public class Cliente {
    public virtual int id               { set; get; }
    public virtual string nome          { set; get; }
    public virtual string cpf           { set; get; }
    public virtual DateTime nascimento  { set; get; }
}
[Serializable]
public class Conta {    
    public virtual long id                      { set; get; }
    public virtual Cliente cliente              { set; get; }
    public virtual String historico             { set; get; }
    public virtual DateTime dtLancamento        { set; get; }
    public virtual DateTime dtVencimento        { set; get; }
    public virtual decimal valorFinal           { set; get; }
}
DAO
//JOIN
public IList<Conta> findAllContasReceberAtiva() 
{
      ISession _session = getSession();
      IList<Conta> list = _session.CreateQuery("FROM Conta c " +
          " INNER JOIN c.cliente cli ON (c.cliente.id = cli.id) " +  
          " WHERE (c.tipoConta = 1) AND (c.status = 0) ORDER BY c.dtLancamento ")
         .List<Conta>();
      return list;    
}
If you made the relationship one-to-Many the mapping of the Client and Many-to-one in account I think it would be easier. I wouldn’t need to write sql... if you want I can for example how to map..
– Marco Giovanni
@Marcogiovanni yes, I agree. It’s just that it’s a college job that the professor asked for a
JOINand you’ve seen neh, explain to the teacher that it is autojoin takes anossss...kkk. But I’ve managed to do it here. Thank you– FernandoPaiva
@Fernandopaiva put his solution as a response.
– novic