-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: ICriteria Problem
PostPosted: Tue Jun 20, 2006 7:14 am 
Newbie

Joined: Tue Jun 20, 2006 7:02 am
Posts: 2
Hello,

Hibernate version: 1.1.4322

Name and version of the database you are using: Oracle 9.2.0.1.0


This code (using the ID column) works fine:
Code:
        ITipoPedidoDao tipoPedidoDao = (new NHibernateDaoFactory().GetTipoPedidoDao());
        ICriteria criteria = NHibernateSessionManager.Instance.GetSession().CreateCriteria(typeof(TipoPedido));
criteria.Add(Expression.Eq("CodGrupo.ID", 2));
List<TipoPedido> tipoPedido = tipoPedidoDao.GetByCriteria(criteria);


But, If I try to create a criteria using another field, I get error: "could not resolve property:CodGrupo.DescricaoGrupo of ABCDEFG.Faturamento.TipoPedido"

Code:
        ITipoPedidoDao tipoPedidoDao = (new NHibernateDaoFactory().GetTipoPedidoDao());
        ICriteria criteria = NHibernateSessionManager.Instance.GetSession().CreateCriteria(typeof(TipoPedido));
criteria.Add(Expression.Like("CodGrupo.DescricaoGrupo", "Pro"));
List<TipoPedido> tipoPedido = tipoPedidoDao.GetByCriteria(criteria);


mapping XML:
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
  <class name="ABCDEFG.Faturamento.TipoPedido, ABCDEFG" table="T_ADF_PO_Pedido_tipo">
    <id name="ID" column="cod_tipo_pedido" unsaved-value="0">
      <generator class="native" />
    </id>
    <property name="Descricao" column="descricao" />
    <many-to-one name="CodGrupo" class="ABCDEFG.Faturamento.TipoPedidoGrupo, ADFinance" column="COD_PEDIDO_TIPO_GRUPO"/>
  </class>
</hibernate-mapping>


class:

Code:
using System;
using System.Collections.Generic;
using System.Text;
using ABCDEFG;

namespace ABCDEFG.Faturamento
{
    public class TipoPedido : DomainObject<int>
    {
        private string descricao;
        public string Descricao
        {
            get { return descricao; }
            set { descricao = value; }
        }

        private TipoPedidoGrupo codGrupo;
        public TipoPedidoGrupo CodGrupo
        {
            get { return codGrupo; }
            set { codGrupo = value; }
        }

        public TipoPedido() { }
    }
}


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 20, 2006 11:30 am 
Expert
Expert

Joined: Fri May 13, 2005 5:56 pm
Posts: 308
Location: Santa Barbara, California, USA
you cannot use sublevel properties/collections in ICriteria, you have to create a subcriteria. the id works because the collection cache only holds the identifiers of each object in the collection. try this:

Code:
ITipoPedidoDao tipoPedidoDao = (new NHibernateDaoFactory().GetTipoPedidoDao());
ICriteria criteria = NHibernateSessionManager.Instance.GetSession().CreateCriteria(typeof(TipoPedido))
    .CreateCriteria(typeof(CodGrupo))
        .Add(Expression.Like("DescricaoGrupo", "Pro"));

List<TipoPedido> tipoPedido = tipoPedidoDao.GetByCriteria(criteria);


Top
 Profile  
 
 Post subject: Thanks
PostPosted: Tue Jun 20, 2006 4:38 pm 
Newbie

Joined: Tue Jun 20, 2006 7:02 am
Posts: 2
Thanks for your reply. It's solved my problem.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.