http://opensource.atlassian.com/projects/hibernate/browse/HHH-153

I think that this issue is still broken - there is no option for join fetching the key-many-to-one. This is important for the criteria queries with restrictions on properites from the class key-many-to-one references to.


** Issue description:

DTD doesn't define it:
<!ELEMENT key-many-to-one (meta*,column*)>
        <!ATTLIST key-many-to-one name CDATA #REQUIRED>
        <!ATTLIST key-many-to-one access CDATA #IMPLIED>
        <!ATTLIST key-many-to-one class CDATA #IMPLIED>
        <!ATTLIST key-many-to-one entity-name CDATA #IMPLIED>
        <!ATTLIST key-many-to-one column CDATA #IMPLIED>
        <!ATTLIST key-many-to-one foreign-key CDATA #IMPLIED>
        <!ATTLIST key-many-to-one lazy (false|proxy) #IMPLIED>

and when in my application it fetches it using select mode. I have a class ForumDescription whith a composite key mapped as:

<hibernate-mapping
>
    <class
        name="ForumDescriptionEntity"
        table="Forums_Lang"
        lazy="false"
        mutable="true"
    >
        <cache usage="read-write" />

        <composite-id
            name="id"
            class="ForumDescriptionEntityId"
        >

                    <key-many-to-one
                        name="forum"
                        class="ForumEntity"
                        column="forum_id"
                        lazy="false"
                    />

                    <key-many-to-one
                        name="country"
                        class="CountryEntity"
                        column="country_id"
                        lazy="false"
                    />

        </composite-id>
.....
   <class
        name="ForumEntity"
        table="Forums"
        lazy="false"
        mutable="true"
    >
        <cache usage="read-write" />

        <id
            name="id"
            column="forum_id"
            type="java.lang.Integer"
            unsaved-value="null"
        >
            <generator class="native"/>
        </id>

For the query:
s.createCriteria(ForumDescriptionEntity.class)
                 .add(Restrictions.eq("disabled", 0)).list();

Hibernate generates:
16:47:28,546 INFO  [STDOUT] Hibernate: /* criteria query */
select this_.forum_id as forum1_1_, this_.country_id as country2_1_, this_.change_timestamp as change3_17_1_, this_.forum_name as forum4_17_1_, this_.forum_description as forum5_17_1_, this_.disabled as disabled17_1_, this_.user_id as user7_17_1_, userentity2_.user_id as user1_0_, userentity2_.user_name as user2_58_0_ from Forums_Lang this_, Users userentity2_ where this_.user_id=userentity2_.user_id(+) and this_.disabled=?

16:47:28,562 INFO  [STDOUT] Hibernate: /* load ForumEntity */
select forumentit0_.forum_id as forum1_1_, forumentit0_.change_timestamp as change2_16_1_, forumentit0_.disabled as disabled16_1_, forumentit0_.forum_type as forum4_16_1_, forumentit0_.priority as priority16_1_, forumentit0_.show_index as show6_16_1_, forumentit0_.user_id as user7_16_1_, forumentit0_.list_type_id as list8_16_1_, userentity1_.user_id as user1_0_, userentity1_.user_name as user2_58_0_ from Forums forumentit0_, Users userentity1_ where forumentit0_.user_id=userentity1_.user_id(+) and forumentit0_.forum_id=?


That's more-less fine. The only problem is performance - both queries can be done as one to save space.

The real problem comes with criteria queries which have restrictions to key-many-to-one classes:
        
s.createCriteria(com.flobec.common.entities.ForumDescriptionEntity.class)
          .createCriteria("id.forum")
          .add(Restrictions.eq("disabled", 0))
(to evaluate disabled protery from ForumEntityClass).

Hibernate generates:
2005-05-27 10:40:17,828 INFO [STDOUT] Hibernate: /* criteria query */ select this_.forum_id as forum1_1_, this_.country_id as country2_1_, this_.change_timestamp as change3_17_1_, this_.forum_name as forum4_17_1_, this_.forum_description as forum5_17_1_, this_.disabled as disabled17_1_, this_.user_id as user7_17_1_, userentity3_.user_id as user1_0_, userentity3_.user_name as user2_58_0_

from Forums_Lang this_, Users userentity3_ where this_.user_id=userentity3_.user_id(+) and forumentit1_.disabled=?

10:40:17,906 ERROR [JDBCExceptionReporter] [-8010] (at 433): Table name must be
in from list

*puff* exception. Table Forums is not in the FROM list. The query seems to be ok. The WHERE clause looks good. But there is no join with the Forums class. Hibernate probably wants to read this class later.
fetch="join" would fix this problem.





--
Jarek Woloszyn
_________________________________________
AKRA GmbH
Domstraße 17 - 19
20095 Hamburg

Tel.  +49 (0) 40 309 535 - 46
Fax.  +49 (0) 40 309 535 - 49
Mob.  +49 (0) 160 / 905 132 23
_________________________________________
mailto:[EMAIL PROTECTED]
http://www.akra.de




-------------------------------------------------------
This SF.Net email is sponsored by Yahoo.
Introducing Yahoo! Search Developer Network - Create apps using Yahoo!
Search APIs Find out how you can build Yahoo! directly into your own
Applications - visit http://developer.yahoo.net/?fr=offad-ysdn-ostg-q22005
_______________________________________________
hibernate-devel mailing list
hibernate-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/hibernate-devel

Reply via email to