-->
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: hibernate3 query with a joined-subclass doesn't work
PostPosted: Fri Jul 22, 2005 9:21 pm 
Beginner
Beginner

Joined: Tue Apr 12, 2005 9:15 pm
Posts: 24
I have a class B which is a joined-subclass of class A. I have a class T that has a set of class B. I have a property "property1" defined on the root class class A. I have a HQL query that is on the joined-subclass class B:
(select count(xx) from T.B xx
where xx.property1 = :value1) = 1)

This query worked fine in hiernate 2.1. It works fine with hibernate3 if I set hibernate.query.factory_class=org.hibernate.hql.classic.ClassicQueryTranslatorFactory

However, if I do not set hibernate.query.factory_class at all, it doesn't work. Hibernate debug shows the sql generated as:
AbstractBatcher:324 (select count(B0_.obid) from B B0_,T T0_ where T0_.id=B0_.id and B_0_.property1=?)=1

The sql I see in hibernate 2.1 and which works has the root class A of the joined-subclass as an inner join :
QueryTranslatorImpl:240 - SQL (select count(B0_.obid) from B B0_ inner join A B_0_ on B_.key=B_0_.key, T T0_ where T0_.id=B0_.id and B_0_.property1=?)=1

For some reason, the hibernate3 generated query doesn't have the inner join to the root class. Not sure what I need to do to make this query work with hibernate3.


The error I get in hibernate3 is
java.sql.SQLException: Unknown column 'B_0_.property1 in 'where clause'
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2847)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1531)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1622)
at com.mysql.jdbc.Connection.execSQL(Connection.java:2376)
at com.mysql.jdbc.Connection.execSQL(Connection.java:2297)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1860)
at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1705)
at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeQuery(NewProxyPreparedStatement.java:414)
at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:120)
at org.hibernate.loader.Loader.getResultSet(Loader.java:1272)
at org.hibernate.loader.Loader.doQuery(Loader.java:391)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:218)
at org.hibernate.loader.Loader.doList(Loader.java:1593)
at org.hibernate.loader.Loader.list(Loader.java:1577)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:395)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:271)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:844)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:74)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 22, 2005 10:06 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
That is NOT valid HQL.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jul 23, 2005 1:13 pm 
Beginner
Beginner

Joined: Tue Apr 12, 2005 9:15 pm
Posts: 24
Gavin,
This query "(select count(xx) from T.B xx
where xx.property1 = :value1) = 1) " is part of a complex AND query I have. Need your help to understand how I would include such a query. This query was working fine with hibernate 2, so I was trying to understand what is wrong.

For the objects I have - where object T has set of Objects B (and B is a subclass of A), What I want to acomplish is - I want to return all objects A only if I find exactly one object in the Set of Objects B (on the object A) which matches my condition of xx.property1=:value1. Can you point at what I am doing wrong and what I can do here to make my query work?


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jul 23, 2005 1:16 pm 
Beginner
Beginner

Joined: Tue Apr 12, 2005 9:15 pm
Posts: 24
user1 wrote:
For the objects I have - where object T has set of Objects B (and B is a subclass of A), What I want to acomplish is - I want to return all objects A only if I find exactly one object in the Set of Objects B (on the object A) which matches my condition of xx.property1=:value1. Can you point at what I am doing wrong and what I can do here to make my query work?


sorry, put the wrong class above...please read above text as :
For the objects I have - where object T has set of Objects B (and B is a subclass of A), What I want to acomplish is - I want to return all objects T only if I find exactly one object in the Set of Objects B (which is subclass of A, and the property1 is a property of the root class A) which matches my condition of xx.property1=:value1. Can you point at what I am doing wrong and what I can do here to make my query work?[/


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.