Is there any way I can add/patch quickly? The reason I am intersted is hibernate is making unecessary extra queries to retrieve associate objects. For example I have the following mapping
<?xml version="1.0"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN" "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >
<hibernate-mapping> <class name="fleetcycle.domain.framework.communication.MessageRecipient" table="MESSAGE_RECIPIENT"> <id column="MESSAGE_RECIPIENT_ID" name="Id" type="string" > <generator class="uuid.hex" /> </id> <many-to-one class="fleetcycle.domain.framework.communication.UserMessage" name="UserMessage" not-null="true" outer-join="true" > <column name="USER_MESSAGE_ID" /> </many-to-one> </class> <class name="fleetcycle.domain.framework.communication.UserMessage" table="USER_MESSAGE"> <id column="USER_MESSAGE_ID" name="Id" type="string" > <generator class="uuid.hex" /> </id> <many-to-one class="fleetcycle.domain.framework.security.User" name="senderUser" not-null="true" outer-join="true" > <column name="SENDER_USER_ID" /> </many-to-one> <set inverse="true" name="MessageRecipientSet" lazy="true"> <key column="USER_MESSAGE_ID" /> <one-to-many class="fleetcycle.domain.framework.communication.MessageRecipient" /> </set> </class> </hibernate-mapping>
MessageRecipient has many-to-one relation with UserMessage. When I make query "from MessageRecipient" to retrieve all message recipient objects hibernate is not using join query. It's making individual queries to these 2 tables.
I have 4 entries in message_recipient table so i can see total 5 sql queries being made. One for retrieving data from message_recipient table and 4 queries for retreiving user_message.
Hibernate: select messagerec0_.MESSAGE_RECIPIENT_ID as MESSAGE_1_, messagerec0_.USER_MESSAGE_ID as USER_MES7_ from MESSAGE_RECIPIENT messagerec0_ Hibernate: select usermessag0_.USER_MESSAGE_ID as USER_MES1_2_, usermessag0_.SENDER_USER_ID as SENDER_U8_2_, user1_.USER_ID as USER_ID0_, user1_.LOGIN_ID as LOGIN_ID0_, from USER_MESSAGE usermessag0_ left outer join FC_USER user1_ on usermessag0_.SENDER_USER_ID=user1_.USER_ID where usermessag0_.USER_MESSAGE_ID=? Hibernate: select usermessag0_.USER_MESSAGE_ID as USER_MES1_2_, usermessag0_.SENDER_USER_ID as SENDER_U8_2_, user1_.USER_ID as USER_ID0_, user1_.LOGIN_ID as LOGIN_ID0_, from USER_MESSAGE usermessag0_ left outer join FC_USER user1_ on usermessag0_.SENDER_USER_ID=user1_.USER_ID where usermessag0_.USER_MESSAGE_ID=? Hibernate: select usermessag0_.USER_MESSAGE_ID as USER_MES1_2_, usermessag0_.SENDER_USER_ID as SENDER_U8_2_, user1_.USER_ID as USER_ID0_, user1_.LOGIN_ID as LOGIN_ID0_, from USER_MESSAGE usermessag0_ left outer join FC_USER user1_ on usermessag0_.SENDER_USER_ID=user1_.USER_ID where usermessag0_.USER_MESSAGE_ID=? Hibernate: select usermessag0_.USER_MESSAGE_ID as USER_MES1_2_, usermessag0_.SENDER_USER_ID as SENDER_U8_2_, user1_.USER_ID as USER_ID0_, user1_.LOGIN_ID as LOGIN_ID0_, from USER_MESSAGE usermessag0_ left outer join FC_USER user1_ on usermessag0_.SENDER_USER_ID=user1_.USER_ID where usermessag0_.USER_MESSAGE_ID=? Hibernate: select usermessag0_.USER_MESSAGE_ID as USER_MES1_2_, usermessag0_.SENDER_USER_ID as SENDER_U8_2_, user1_.USER_ID as USER_ID0_, user1_.LOGIN_ID as LOGIN_ID0_, from USER_MESSAGE usermessag0_ left outer join FC_USER user1_ on usermessag0_.SENDER_USER_ID=user1_.USER_ID where usermessag0_.USER_MESSAGE_ID=?
Is there any thing I miss in my mapping? or is it a desired hibernate behavior?
|