rapaz...pra fazer join vc tem q ter um objeto bag no seu hbm e um
objeto do tipo da classe q vc ira fazer o join
não entendo muito bem vb mas em c# eu faço assim....
tipo eu tenho um classe usuario, uma pessoa...assim fica meu hbm...e o
cs
hbm:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
assembly="RGTIOR" namespace="RGTIOR">
<class name="Usuario" table="Usuario">
<id name="IdPessoa" column="idPessoa" type="Decimal" unsaved-
value="0">
<generator class="foreign">
<param name="property">fkPessoa</param>
</generator>
</id>
<property column="cpf" type="String" name="Cpf" length="11"/>
<one-to-one name="fkPessoa" class="Pessoa" constrained="true"
cascade="all"/>
</class>
</hibernate-mapping>
cs
using System;
using System.Collections.Generic;
namespace RGTIOR
{
[Serializable]
public class Usuario : IEquatable<Usuario>
{
#region Private Members
private decimal _idpessoa;
private Pessoa _fkPessoa;
private string _cpf;
#endregion
#region Constructor
public Usuario()
{
_idpessoa = 0;
_fkPessoa = new Pessoa();
_cpf = "";
}
public Usuario(bool novo)
{
_idpessoa = 0;
_fkPessoa = new Pessoa(true);
_cpf = "";
}
#endregion // End of Default ( Empty ) Class Constuctor
#region Required Fields Only Constructor
/// <summary>
/// required (not null) fields only constructor
/// </summary>
public Usuario(
decimal idpessoa)
: this()
{
_idpessoa = idpessoa;
}
#endregion // End Constructor
#region Public Properties
public virtual decimal IdPessoa
{
get
{
return _idpessoa;
}
set
{
_idpessoa = value;
}
}
public virtual Pessoa fkPessoa
{
get
{
return _fkPessoa;
}
set
{
_fkPessoa = value;
}
}
public virtual string Cpf
{
get
{
return _cpf;
}
set
{
_cpf = value;
}
}
#endregion
#region Public Functions
public static IList<Usuario> RetornaUsuario(string colum, string tipo,
string filtro)
{
try
{
string hql = @"
From Usuario us
left join fetch us.fkPessoa um ";
if (filtro != null && colum != null)
{
if (filtro.Trim() != "" && colum != "")
{
hql += " where "+colum+" LIKE ? ";
}
}
if (colum != null)
{
if (colum.Trim() != "")
{
hql += " order by " + colum + " " + tipo;
}
}
IQuery q =
NHibernateHelper.GetCurrentSession().CreateQuery(hql);
if (filtro != null && colum != null)
{
if (filtro.Trim() != "" && colum != "")
{
q.SetString(0, "%" + filtro+"%");
}
}
return q.List<Usuario>();
}
catch (Exception ex)
{
throw ;
}
}
#endregion //Public Functions
#region Equals And HashCode Overrides
/// <summary>
/// local implementation of Equals based on unique value
members
/// </summary>
public override bool Equals(object obj)
{
if (this == obj) return true;
if ((obj == null) || (obj.GetType() != this.GetType()))
return false;
Usuario castObj = (Usuario)obj;
return (castObj != null) &&
(this._idpessoa == castObj.IdPessoa);
}
/// <summary>
/// local implementation of GetHashCode based on unique value
members
/// </summary>
public override int GetHashCode()
{
int hash = 57;
hash = 27 ^ hash ^ _idpessoa.GetHashCode();
return hash;
}
#endregion
#region IEquatable members
public bool Equals(Usuario other)
{
if (other == this)
return true;
return (other != null) &&
(this._idpessoa == other.IdPessoa);
}
#endregion
}
}
no cs tenho a seguinte função q faz o join
public static IList<Usuario> RetornaUsuario(string colum, string tipo,
string filtro)
{
try
{
string hql = @"
From Usuario us
left join fetch us.fkPessoa um ";
if (filtro != null && colum != null)
{
if (filtro.Trim() != "" && colum != "")
{
hql += " where "+colum+" LIKE ? ";
}
}
if (colum != null)
{
if (colum.Trim() != "")
{
hql += " order by " + colum + " " + tipo;
}
}
IQuery q =
NHibernateHelper.GetCurrentSession().CreateQuery(hql);
if (filtro != null && colum != null)
{
if (filtro.Trim() != "" && colum != "")
{
q.SetString(0, "%" + filtro+"%");
}
}
return q.List<Usuario>();
}
catch (Exception ex)
{
throw ;