Hello guys. I'm having some problems with NHibernate when it comes to mapping many to many relationships, specially this one.
I have a Category table, which each parent can have as many childs as it needs, and it can be also a parent.
When i try to select something from category table, i get an error:
ERROR: 42601: syntax error at or near "."
Any chance you might figure it out why is throwing this error?
THanks a lot guys
Heres the select
System.Collections.IList resultado2 = sessao.Find("select c.IdCategoria,c.NomeCategoria,c.CategoriasFilhas from Categoria c");
Heres the table
CREATE TABLE category
(
id_cat serial not null,
id_cat_p integer not null,
nm_cat string (256) not null,
...
);
my c# class
public class Categoria
{
private int idCategoria;
private string nmCategoria;
private int nivelCategoria;
private int rankCategoria;
private IList<Categoria> categoriasFilhas;
public virtual int IdCategoria
{
get { return this.idCategoria; }
set { this.idCategoria = value; }
}
public virtual string NomeCategoria
{
get { return this.nmCategoria; }
set { this.nmCategoria = value; }
}
public virtual int NivelCategoria
{
get { return this.nivelCategoria; }
set { this.nivelCategoria = value; }
}
public virtual int RankCategoria
{
get { return this.rankCategoria; }
set { this.rankCategoria = value; }
}
public virtual IList<Categoria> CategoriasFilhas
{
get { return this.categoriasFilhas; }
private set { this.categoriasFilhas = value; }
}
}
And here is the mapping
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="GeoBiblio" namespace="GeoBiblio.Classes.Orm">
<class name="Categoria" table="categoria" discriminator-value="categoria">
<id name="IdCategoria" type="Int32" column="id_categoria" unsaved-value="0" access="property">
<generator class="sequence">
<param name="sequence">categoria_id_categoria_seq</param>
</generator>
</id>
<property name="NomeCategoria" column="nm_categoria" type="String" unique="true"/>
<property name="NivelCategoria" column="nivel_categoria" type="Int32"/>
<property name="RankCategoria" column="rank_categoria" type="Int32"/>
<bag name="CategoriasFilhas" table="categoria" fetch="select" inverse="true" lazy="true">
<key column="id_categoria_pai"/>
<many-to-many class="Categoria" column="id_categoria" order-by="rank_categoria"/>
</bag>
</class>
</hibernate-mapping>