User "select distinct".
Jon Anderson wrote:
Not sure if this is a bug or not, so feel free to tell me to get lost! =)
I have two tables, Data and Type. Type is a self referential table, allowing grouping of Types. (In my hibernate mapping, type_id reference is mapped as a many-to-on on method get/setSuperType )
CREATE TABLE Type ( id integer IDENTITY PRIMARY KEY, type_id integer, name varchar, FOREIGN KEY (type_id) REFERENCES Type(id) )
CREATE TABLE Data ( id integer IDENTITY PRIMARY KEY, type_id integer, data text, FOREIGN KEY (type_id) REFERENCES Type(id) )
I'm trying to get all data for a type that is relevant:
from Data as d where d.type is null or
d.type.id = 1448 or
d.type.superType.id = 1448
This in turn generates the following SQL:
select data0_.id as id, data0_.type_id as type_id, data0_.question as data from data data0_, type type1_ where (data0_.type_id is null )
or (data0_.type_id=1448 )
or (type1_.type_id=1448 and data0_.type_id=type1_.id)
As you can see, the first 2 where conditions leave the Type table unbound, so I get a result for every entry in the Type table. If I add an explicit join in my HQL :
from Data as d join d.type as t
where d.type is null or
d.type.id = 1448 or
d.type.superType.id = 1448
I get correct results. Is this a bug (I'd think the join should be added with the reference to superType), or is "just they way things work(TM)"?
Thanks, Jon
------------------------------------------------------- This SF.net email is sponsored by: IBM Linux Tutorials. Become an expert in LINUX or just sharpen your skills. Sign up for IBM's Free Linux Tutorials. Learn everything from the bash shell to sys admin. Click now! http://ads.osdn.com/?ad_id=1278&alloc_id=3371&op=click _______________________________________________ hibernate-devel mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/hibernate-devel
-- Gavin King JBoss Group +61 410534454 http://hibernate.org
------------------------------------------------------- This SF.net email is sponsored by: IBM Linux Tutorials. Become an expert in LINUX or just sharpen your skills. Sign up for IBM's Free Linux Tutorials. Learn everything from the bash shell to sys admin. Click now! http://ads.osdn.com/?ad_id=1278&alloc_id=3371&op=click _______________________________________________ hibernate-devel mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/hibernate-devel