-->
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.  [ 4 posts ] 
Author Message
 Post subject: Using UNION on sql
PostPosted: Wed Oct 19, 2005 2:45 pm 
Beginner
Beginner

Joined: Thu Feb 05, 2004 9:09 am
Posts: 27
Hibernate version:3.0.5
Name and version of the database you are using:Oracle 10g

This my program:
StringBuffer sf = new StringBuffer("");
sf.append(" from Parlamentar pl ");
sf.append(" join ( ");
sf.append(" select ipl.id from Parlamentar ipl where ipl.nomeCivil like ('%JOSE%') ");

sf.append(" union ");

sf.append(" select npl.id from Parlamentar npl where npl.nomesParlamentares.nomeParlamentar like ('%JOSE%') ");
sf.append(" ) np on pl.id = np.id ");

Query query = configuration.getCurrentSession().createQuery(sf.toString());

List colecao = query.list();

This my exception:
unexpected token: ( near line 1, column 71

This generate sql debug :
from br.gov.camara.procede.silegdep.comum.model.Parlamentar pl join ( select ipl.id from br.gov.camara.procede.silegdep.comum.model.Parlamentar ipl where ipl.nomeCivil like ('%sev%') union select npl.id from br.gov.camara.procede.silegdep.comum.model.Parlamentar npl where npl.nomesParlamentares.nomeParlamentar like ('%sev%') ) np on pl.id = np.id

What´s wrong?


Top
 Profile  
 
 Post subject: Re: Using UNION on sql
PostPosted: Wed Oct 19, 2005 2:56 pm 
Expert
Expert

Joined: Mon Feb 14, 2005 12:32 pm
Posts: 609
Location: Atlanta, GA - USA
far56 wrote:
Hibernate version:3.0.5
Name and version of the database you are using:Oracle 10g

This my program:
StringBuffer sf = new StringBuffer("");
sf.append(" from Parlamentar pl ");
sf.append(" join ( ");
sf.append(" select ipl.id from Parlamentar ipl where ipl.nomeCivil like ('%JOSE%') ");

sf.append(" union ");

sf.append(" select npl.id from Parlamentar npl where npl.nomesParlamentares.nomeParlamentar like ('%JOSE%') ");
sf.append(" ) np on pl.id = np.id ");

Query query = configuration.getCurrentSession().createQuery(sf.toString());

List colecao = query.list();

This my exception:
unexpected token: ( near line 1, column 71

This generate sql debug :
from br.gov.camara.procede.silegdep.comum.model.Parlamentar pl join ( select ipl.id from br.gov.camara.procede.silegdep.comum.model.Parlamentar ipl where ipl.nomeCivil like ('%sev%') union select npl.id from br.gov.camara.procede.silegdep.comum.model.Parlamentar npl where npl.nomesParlamentares.nomeParlamentar like ('%sev%') ) np on pl.id = np.id

What´s wrong?


Your query is invalid.

from Parlamentar pl join (???? What are you joining to ?

In HQL, joins must be to an associated object. For example,

Code:
from Parlamentar pl join pl.someAttribute sa

will join the Parlamentar table to the SomeAttribute table.

_________________
Preston

Please don't forget to give credit if/when you get helpful information.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 20, 2005 7:35 am 
Beginner
Beginner

Joined: Thu Feb 05, 2004 9:09 am
Posts: 27
Thank´s for your help, but I need to do a UNION. How?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 20, 2005 7:57 am 
CGLIB Developer
CGLIB Developer

Joined: Thu Aug 28, 2003 1:44 pm
Posts: 1217
Location: Vilnius, Lithuania
Create view for this kind of queries.


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