Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
I am doing performance optimization for my application. One of the concerns is that while doing a select, columns are getting selected twice. Like in the following case, the select query is fetching parentid and userid both, two times. I noticed that in queries involving the entire object, whatever is defined in the <key> field of the map also gets selected, even if it is defined before in the file. Like in this case, the parentid and userid get selected multiple times. Does somebody have an idea why this is happening? Is there something that I can change in the mapping file, so that it selects the field just once?
Thanks,
smsea.
Hibernate version:
3
Mapping documents:
<class name="Members" table="members">
<composite-id name="MemberId" class="MemberId">
<!-- The component fields of the composite primary key -->
<key-property name="Parentid" column="parentid" type="long" />
<key-property name="Userid" column="userid" type="customtype.UserIdUserType"/>
</composite-id>
<map name="memberAttributes" lazy="false" table="MemberAttribute" cascade="all" >
<!-- The primary key of the class (Required for the <map> tag)-->
<key>
<column name="parentid" not-null="true"/>
<column name="userid" not-null="true"/>
</key>
<!-- Specifies the index of the memberAttributes Map to be the attribute name string-->
<map-key type="string" column="attribute_name" />
<!-- Specifies that the memberAttributes Map stores string attribute values as its elements-->
<element type="string" column="attribute_value"/>
</map>
</class>
Code between sessionFactory.openSession() and session.close():
Full stack trace of any exception that occurs:
Name and version of the database you are using:
The generated SQL (show_sql=true):
Hibernate: select this_.parentid as associat1_1_, this_.owner_profileid as owner2_0_1_, this_.application_type as applicat3_0_1_,
members2_.Parentid as associat1_3_, members2_.Userid as Profileid3_, members2_.userid as profileid3_, members2_.parentid as associat1_0_, members2_.Userid as Profileid0_, associatio3_.parentid as associat1_4_, associatio3_.attribute_value as attribute2_4_, associatio3_.attribute_name as attribute3_4_ from parenttable this_, members members2_, MemberAttribute associatio3_ where this_.parentid=members2_.parentid(+) and this_.parentid=associatio3_.parentid(+) and (this_.owner_profileid=? and this_.application_type=? )
Debug level Hibernate log excerpt: