-->
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.  [ 7 posts ] 
Author Message
 Post subject: Subqueries.exists Criteria
PostPosted: Mon May 16, 2005 2:02 pm 
Newbie

Joined: Mon May 16, 2005 1:45 pm
Posts: 2
Hibernate version: Hibernate 3.0.3

Db: MySql 4.1.7

When trying to use Criteria.add(Subqueries.exists(DetachedCriteria)), I have the following problem:

Working with the DetachedCriteria only by itself works, but when adding this to Criteria.add(Subqueries.exists(...)), it generates invalid sql.

-------------------------------------------------------------------------
Working example Example with using only the DetachedCriteria:

/** article version has collection of chapters, chapter has collection of textBlocks **/
DetachedCriteria dt=
DetachedCriteria.forClass(ArticleVersion.class)
.setProjection(Property.forName("id"))
.createAlias("chapters","chapters")
.createAlias("chapters.textBlocks","textBlocks")
.add(Restrictions.eq("textBlocks.mediaObject.id","M050516ANOND000003"))
;

Criteria criteria=dt.getExecutableCriteria(session);

List<MediaObject> result=criteria.list();
System.out.println(result);

The generated sql is:
Hibernate: select this_.info_object_version as y0_ from wub_article_versions this_ inner join wub_info_object_versions this_1_ on this_.info_object_version=this_1_.id inner join wub_article_chapters chapters1_ on this_.info_object_version=chapters1_.article_version inner join wub_article_textblocks textblocks2_ on chapters1_.id=textblocks2_.parent_chapter where textblocks2_.media_object=?


-------------------------------------------------------------------------
Not working example - probably bug; just use the previously defined criteria in Criteria.add(Subqueries.exists(...))


Criteria criteria=session.createCriteria(MediaObject.class);

DetachedCriteria dt=
DetachedCriteria.forClass(ArticleVersion.class)
.setProjection(Property.forName("id"))
.createAlias("chapters","chapters")
.createAlias("chapters.textBlocks","textBlocks")
.add(Restrictions.eq("textBlocks.mediaObject.id","M050516ANOND000003"))
;

criteria.add(
Subqueries.exists(dt)
);

List<MediaObject> result=criteria.list();
System.out.println(result);

The generated sql is (textblocks2_ alias is not defined, why ?):
Hibernate: select this_.id as id0_, this_.created as created16_0_, this_.credit as credit16_0_, this_.caption as caption16_0_, this_.id_sequence_val as id5_16_0_, this_.display_text as display6_16_0_, this_.expires as expires16_0_, this_.fee_duty as fee8_16_0_, this_.keywords as keywords16_0_, this_.modified as modified16_0_, this_.rubric as rubric16_0_, this_.media_group as media12_16_0_, this_.created_by as created13_16_0_, this_.modified_by as modified14_16_0_, this_.perview_height as perview15_16_0_, this_.preview_height_original as preview16_16_0_, this_.preview_path as preview17_16_0_, this_.preview_width as preview18_16_0_, this_.preview_width_original as preview19_16_0_, this_.deleted as deleted16_0_, this_.deleted_by as deleted21_16_0_, this_.deleted_time as deleted22_16_0_ from wub_media_objects this_ where exists (select this0__.info_object_version as y0_ from wub_article_versions this0__ inner join wub_info_object_versions this0__1_ on this0__.info_object_version=this0__1_.id where textblocks2_.media_object=?)

And the exception:
Exception in thread "main" org.hibernate.exception.SQLGrammarException: could not execute query
at org.hibernate.exception.ErrorCodeConverter.convert(ErrorCodeConverter.java:70)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.loader.Loader.doList(Loader.java:1565)
at org.hibernate.loader.Loader.list(Loader.java:1545)
at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:111)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1316)
at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:299)
at Test.main(Test.java:218)
Caused by: java.sql.SQLException: Unknown column 'textblocks2_.media_object' in 'where clause'
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:1997)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1167)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1278)
at com.mysql.jdbc.Connection.execSQL(Connection.java:2247)
at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1586)
at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:118)
at org.hibernate.loader.Loader.getResultSet(Loader.java:1239)
at org.hibernate.loader.Loader.doQuery(Loader.java:374)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:210)
at org.hibernate.loader.Loader.doList(Loader.java:1562)
... 5 more

Could anyone please help me or giv me a hint ? thanks


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 16, 2005 2:04 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
this is a well-known bug


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 16, 2005 2:07 pm 
Newbie

Joined: Mon May 16, 2005 1:45 pm
Posts: 2
Do you know if it is gonna be repaired and when ?

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 17, 2005 4:13 am 
Newbie

Joined: Fri Apr 22, 2005 9:50 am
Posts: 2
Location: Germany
What is the JIRA ticket id for this issue ? I submitted bug HHH478 which was closed as duplicate by Gavin. Unfortunately I cannot find the original ticket, so if someone is monitoring this bug also, please post the ticket id here.


Top
 Profile  
 
 Post subject: status check - similar issue?
PostPosted: Fri Sep 09, 2005 4:35 pm 
Newbie

Joined: Fri Mar 25, 2005 1:16 pm
Posts: 13
Anyone know the status of this one? I can't find anything regarding this in JIRA. My problem is somewhat different, but the setup seems the same. I have a detached query that generates sql fine. However, when I use Suqueries.exists to add it as an exists on my main query, the generated sql does not have the joins for the subquery.

Alone:
select id from foo f join bar b on f.barId = b.id where b.prop = 'z'

As exists subquery:
select id from foo f where b.prop = 'z'

The latter fails with unknown table or alias b. Is this problem related, or separate? In SubqueryExpression, where the sql is generated, Select.setOuterJoins is not called like it is elsewhere (AbstractEntityJoinWalker for one).

This is 3.1beta1, but SubqueryExpression has not changed in HEAD.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 09, 2005 6:37 pm 
Newbie

Joined: Fri Mar 25, 2005 1:16 pm
Posts: 13
In CriteriaQueryTest.java, it appears that this is known to be an issue. Is there any implementation timeline?

Code:
      //TODO: join in subselect
      /*DetachedCriteria dc3 = DetachedCriteria.forClass(Student.class, "st")
         .createCriteria("enrolments")
            .createCriteria("course")
               .add( Property.forName("description").eq("Hibernate Training") )
               .setProjection( Property.forName("st.name") );
   
      session.createCriteria(Enrolment.class, "e")
         .add( Subqueries.eq("Gavin King", dc3) )
         .list();*/


Top
 Profile  
 
 Post subject:
PostPosted: Sun Dec 25, 2005 10:01 pm 
Beginner
Beginner

Joined: Fri Jul 22, 2005 3:35 pm
Posts: 24
Location: Buenos Aires, Argentina
For reference: This appears as issue HHH-952: http://opensource2.atlassian.com/projec ... se/HHH-952 .


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