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.  [ 2 posts ] 
Author Message
 Post subject: Proxies and Subclasses
PostPosted: Mon Jun 11, 2007 6:05 pm 
Newbie

Joined: Mon Jun 11, 2007 4:35 pm
Posts: 1
Hello, I'm using NHibernate 1.2GA and I'm confronting with difficulty.

Here goes the situation:

I've the following model (resumed):

Code:
public  class Lancamento //discriminator value 0
{
   Int64 id;
   Double valor;
   Byte situacao;
   DateTime vencimento;
   Int32 numeroParcela;
   Operacao operacao;
}

public  class Recebimento : Lancamento //discriminator value 1
{
}

public  class AReceber : Recebimento //discriminator value 3
{
}

public  class Pagamento : Lancamento //discriminator value 2
{
}

public  class APagar : Pagamento //discriminator value 4
{
}

public  class Operacao //discriminator value 0
{
   Int64 id;
   Int64 codigoInterno;
   String numeroDocumento;
   String descricao;
   DateTime data;
   Double valor;
   Byte situacao;
   Int32 numeroTerminal;
   String observacao;
   IList lancamentos;
}

public class Receita : Operacao //discriminator value 1
{
}

public  class Venda : Receita //discriminator value 4
{
}

public class Despesa : Operacao //discriminator value 2
{
}

public  class Compra : Despesa //discriminator value 5
{
}

public  class Baixa : Operacao //discriminator value 3
{
}


All classes and subclasses is mapped with the proxy attribute equally the attribute name in the class node (As I see in the section '15.1.3. Single-ended association proxies' in NHibernate Documentation) and lazy=true.
In theory the types Lancamento and Operacao is never used.

So when I query for class 'Lancamento', the property 'operacao' gives me a proxied instance of the classes (Eg.: CProxyType.....Venda or CProxyType.....Compra) inherited from class 'Operacao'.
Then when I try to ask (in C#) '(Lancamento.Operacao is Venda)', for a item wich 'obviously' is a Venda, it returns me 'false', because 'Lancamento.Operacao.GetType()' is equal to 'CProxyType.....Venda'. It is a subclass of 'Operacao' but not is a 'Venda'.

I found an alternative to this situation using NHibernate.NHibernateUtil.GetClass(), or make a join, but it cause slow down of performance or some pollution to my code, and I can't make a cast to correct type (Eg.: (Venda)Lancamento.operacao).

In really I want to make a suggestion:

It would be nice if there's an option to create the correct class when I access this property.
But if there's another way to automatically returns the correct type without use join or NHibernate.NHibernateUtil.GetClass(), please tell me.


Thanks everybody.
Alex


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 20, 2008 3:20 pm 
Newbie

Joined: Fri Mar 07, 2008 10:01 pm
Posts: 3
Alex, eu estou tendo o mesmo problema, tenho uma grid e dentro da grid outra grid com os ralacionamentos da linha, entao quando quando eu teleto uma das linha da subgrid e tento dar um refresh na grid pai, a primeira linha vem com o tipo CProxy e acaba dando erro no bind. mas isso nao acontece sempre... acho q e algum bug do hibernate...

eu vi falar sobre alguma coisa de cache, tipo quendo tem uma sessao do objeto no cache e vc da um load nele denovo ele vem com esse tipo...

quando souber de alguma coisa fala comigo... abraços

uncodead@gmail.com

thanks


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.