-->
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.  [ 5 posts ] 
Author Message
 Post subject: Column alias trouble
PostPosted: Tue Apr 13, 2010 6:33 am 
Newbie

Joined: Wed Sep 09, 2009 4:15 am
Posts: 14
Hello, i have a little troble with Hibernate.
In my query I have these Criteria "c":

c.add(Restrictions.ne("codClasse", "49"));
c.add(Restrictions.ne("codClasse", "51"));


When it runs i get: ORA-00904: "Y5_": invalid identifier
And the logged SQL query is:

select distinct this_.COD_BANCA as y0_, this_.DESC_BANCA as y1_, this_.COD_ENTITA as y2_, this_.INTESTAZIONE_MEDIA as y3_, this_.COD_ENTITA_PADRE as y4_, this_.COD_CLASSE as y5_ from MYTABLE this_ where this_.COD_ENTITA_PADRE like ? and this_.FLAG_AUT_CONT like ? and this_.COD_CLASSE_PADRE like ? and not
y5_ like ? and not y5_ like ? and this_.COD_TIPOL_UO in (?, ?, ?, ?)

As you can se in the restrictions is used the column alias (y5_) intead of the column name like in the other restrictions... why?
Thank you.


Top
 Profile  
 
 Post subject: Re: Column alias trouble
PostPosted: Tue Apr 13, 2010 9:17 am 
Newbie

Joined: Wed Sep 09, 2009 4:15 am
Posts: 14
I found the cause, i report this just if someone else will find the same problem.

The trouble was the projection with the same name as the Entity propertyName:

c.add(Restrictions.ne("codClasse", "49"));
c.add(Restrictions.ne("
codClasse", "51"));
...
projList.add(Projections.property("
codClasse"), "codClasse");

Changing the projection variable (or the entity property) i solved:

c.add(Restrictions.ne("codClasse", "49"));
c.add(Restrictions.ne("
codClasse", "51"));
...
projList.add(Projections.property("
codClasse"), "classe");

I hope it will be useful... i spent a morning for this!


Top
 Profile  
 
 Post subject: Re: Column alias trouble
PostPosted: Thu Aug 26, 2010 12:50 pm 
Beginner
Beginner

Joined: Thu Jul 08, 2004 8:56 am
Posts: 23
I am having the same issue here.
Isn't anyone going to file a bug for this?
Definitely it is a bug as it is not stated in any part of the docs that this isn't allowed and it does not seem that unusual to project a field on a bean property with the same name.
Strangely enough ppl tried to file bugs and they got rejected even though later on it was clearly stated on the bug reports the way to reproduce the error:
http://opensource.atlassian.com/projects/hibernate/browse/HHH-1685
http://opensource.atlassian.com/projects/hibernate/browse/HHH-2847

_________________
Rafael Ribeiro


Top
 Profile  
 
 Post subject: Re: Column alias trouble
PostPosted: Thu Aug 26, 2010 12:56 pm 
Beginner
Beginner

Joined: Thu Jul 08, 2004 8:56 am
Posts: 23
Tobia,

There is an uglier hack that can be applied in the meantime. Suppose your entity is called MyEntity, you should do a createCriteria(MyEntity.class, "this") and then change the restrictions to have this prefix and letting the projection without the prefix:

c.add(Restrictions.ne("this.codClasse", "49"));
c.add(Restrictions.ne("this.codClasse", "51"));
...
projList.add(Projections.property("codClasse"), "codClasse");

_________________
Rafael Ribeiro


Top
 Profile  
 
 Post subject: Re: Column alias trouble
PostPosted: Fri Aug 27, 2010 3:36 am 
Newbie

Joined: Wed Sep 09, 2009 4:15 am
Posts: 14
Thanks rafaelri,
I think your way is better, i will try it!


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