Hi every one,
I have a problem with table alias in subquery. I think that it's a bug in Hibernate 3.6.0 Final. This is my HQL query:
Code:
insert into Item_Tag(itemId, tagId) select item.id, tag.id from Item item, Tag tag where item.identifier like :identifier0 and tag.id in (:tagIds) and not exists (from Item_Tag where itemId = item.id and tagId = tag.id)
And Hibernate translates to native query like this:
Code:
Hibernate: 
    insert 
    into
        item_tag_map
        ( id_item_tag_map, id_item, id_tag ) select
            nextval ('hibernate_sequence'),
            item0_.id_item as col_0_0_,
            tag1_.id_tag as col_1_0_ 
        from
            item_list item0_ cross 
        join
            tag_list tag1_ 
        where
            (
                item0_.identifier like ?
            ) 
            and (
                tag1_.id_tag in (
                    ?
                )
            ) 
            and  not (exists (select
                item_tag2_.id_item_tag_map 
            from
                item_tag_map item_tag2_ 
            where
                item_tag2_.id_item=item_list.id_item 
                and item_tag2_.id_tag=tag_list.id_tag))
As you see, in the subquery, the alias "item" and "tag" are replaced by their raw names: "item_list" and "tag_list". So an exception org.hibernate.util.JDBCExceptionReporter is thrown to indicate that the alias "item0_" and then "tag1_" should be used in this case.
Is there anyone who knows if it's a bug or how to solve this error? Thanks very much.