-->
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.  [ 6 posts ] 
Author Message
 Post subject: Problems with mapping Objects
PostPosted: Tue Apr 26, 2005 3:59 pm 
Newbie

Joined: Tue Apr 26, 2005 3:06 pm
Posts: 14
Location: Vitória - ES - Brasil
Hi All!
I am with a great problem and would like to count on the you aid.
I am trying to execute one query but the "intelligence" of hibernate confuses me a little.
Let us say that I have the following structure of classrooms:
Quote:
A.getId_A()
A.getName()
A.getB() >> return class B
B.getId_B()
B.getName()


If I to execute one query in hibernate in the following format:

Quote:
Select A.Id_A, A.Name, A.B.Id_B , A.B.Name, from A,B where B.Id_B = A.B.Id_B(+)


I would like that hibernate I generated the following one:

Quote:
TA >> TableA
TB >> TableB

Select TA.Id_TA, TA.Nam_TA, TA.Id_TB , TB.Nam_TB from TA,TB where TB.Id_TB = TA.Id_TB(+)


But, as use mapping of objects, A.B.Id_B instead of A.Id_B, hibernate generates the following one:

Quote:
Select i1.Id_TA, i1.Nam_TA, i1.Id_TB , i2.Nam_TB from TA i1 , TB i2, TA i3 , TB i4 where i2.Id_TB = i1.Id_TB(+) and i3.Id_TB = i4.Id_TB


It is not my interest that the second part of where either added, nor that is added again from tables TA and TB.

Somebody knows as I can prevent that these to duplicate are generated or it suggests some alternative to me?

[]`s[/quote]

_________________
Roberto Marconi


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 27, 2005 2:55 pm 
Newbie

Joined: Tue Apr 26, 2005 3:06 pm
Posts: 14
Location: Vitória - ES - Brasil
ninguém? :(

_________________
Roberto Marconi


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 27, 2005 7:21 pm 
Newbie

Joined: Wed Apr 27, 2005 7:05 pm
Posts: 3
refaz o post em portugues, esta meio dificil de entender, talvez eu entenda melhor em portugues.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 28, 2005 8:10 am 
Newbie

Joined: Tue Apr 26, 2005 3:06 pm
Posts: 14
Location: Vitória - ES - Brasil
Estou tentando executar uma query HQL mas a inteligencia do hibernate atrapalha um pouco.

Imagine a seguinte estrutura de classes:
A.getId_A()
A.getName()
A.getB() >> returna a classe B
B.getId_B()
B.getName()

Se eu executo uma query no formato HQL:

Select A.Id_A, A.Name, A.B.Id_B , A.B.Name, from A,B where B.Id_B = A.B.Id_B(+)

Eu queria que hibernate gerasse o seguinte SQL:

TA >> Tabela A
TB >> Tabela B

Select TA.Id_TA, TA.Nam_TA, TA.Id_TB , TB.Nam_TB from TA,TB where TB.Id_TB = TA.Id_TB(+)

Mas, como eu uso mapeamento de objetos, A.B.Id_B ao invés de A.Id_B, hibernate gera o seguinte SQL:

Select i1.Id_TA, i1.Nam_TA, i1.Id_TB , i2.Nam_TB from TA i1 , TB i2, TA i3 , TB i4 where i2.Id_TB = i1.Id_TB(+) and i3.Id_TB = i4.Id_TB

Não é meu interesse a segunda parte gerada pelo hibernate na clausula where, nem que ele adicione novamente as tabelas TA e TB na clausula FROM.

Alguém sabe como posso fazer para que ele não gere esta duplicidade, ou alguem me sugere alguma outra alternativa que não seja SQL nativo, pois são mais de 150 campos e tornaria minha função dificil de dar manutenção?


[]`s
_________________

_________________
Roberto Marconi


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 28, 2005 9:10 am 
Newbie

Joined: Wed Apr 27, 2005 7:05 pm
Posts: 3
Quote:
Select i1.Id_TA, i1.Nam_TA, i1.Id_TB , i2.Nam_TB from TA i1 , TB i2, TA i3 , TB i4 where i2.Id_TB = i1.Id_TB(+) and i3.Id_TB = i4.Id_TB


Parece-me que a query acima daria os mesmos resultados e nao faria o DB funcionar mais devegar. Esta dando resultados errados?

Quote:
Select A.Id_A, A.Name, A.B.Id_B , A.B.Name, from A,B where B.Id_B = A.B.Id_B(+)


Voce ja tentou fazer a mesma query mas usando JOIN? Nao tenho certeza mais talvez elimine as coisas extras no WHERE.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 28, 2005 10:04 am 
Newbie

Joined: Tue Apr 26, 2005 3:06 pm
Posts: 14
Location: Vitória - ES - Brasil
Quote:
Select i1.Id_TA, i1.Nam_TA, i1.Id_TB , i2.Nam_TB from TA i1 , TB i2, TA i3 , TB i4 where i2.Id_TB = i1.Id_TB(+) and i3.Id_TB = i4.Id_TB


Não é a mesma coisa não!

Eu faço um alterjoin >> (+), para que ele traga na consulta tanto os A que possuem B associados, quanto os que não possuem.

como ele monta esete join
Quote:
i3.Id_TB = i4.Id_TB

ele elimina minha possibilidade de trazer atributos null.


Quote:
Select A.Id_A, A.Name, A.B.Id_B , A.B.Name, from A,B where B.Id_B = A.B.Id_B(+)


Já tentei fazendo From A FULL outer join B.
Quando eu preciso fazer 1 só, ele funciona, mas como eu faço:
Quote:
From A Full outer join B, A left outer join C


ele embaralha e faz o join assim mesmo.

_________________
Roberto Marconi


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