I am using Hibernate 2.1.2 with SAPDB 7.4.
The following is the mapping in use for this question
Code:
<list name="assignedFunctionList" table="USERGROUPFUNCTIONS"
lazy="true" inverse="false" cascade="all">
<key column="USERGROUPID" />
<index column="USERGROUPFUNCTIONID" />
<many-to-many
class="com.foo.bar.beans.site.access.Function"
column="FUNCTIONID"
outer-join="false"
/>
</list>
The relationship is used to get a list of assigned Function objects for a UserGroup.
Here is the code to get the many-to-many populated.
Code:
hibernateSession = HibernateManager.currentSession();
userGroup = (UserGroup) hibernateSession.load(UserGroup.class, userGroupId);
/** load lazy objects */
logger.debug("preparing to get functionList: " + userGroup.getAssignedFunctionList());
List functionList = userGroup.getAssignedFunctionList();
logger.debug("functionList has size: " + functionList.size());
There are two relationships in the database for this mapping. However, the following are the log results I get for the two debug messages.
DEBUG [com.foo.bar.dao.site.access.UserGroupDAO] - preparing to get functionList: [null, null, null, null, com.foo.bar.beans.site.access.Function@eb840f, com.foo.bar.beans.site.access.Function@16602cb]
DEBUG [com.foo.bar.dao.site.access.UserGroupDAO] - functionList has size: 6
The table structure is as follows
TABLE USERGROUPS
USERGROUPID INTEGER PK
TABLE FUNCTIONS
FUNCTIONID INTEGER PK
TABLE USERGROUPFUNCTIONS
USERGROUPFUNCTIONID INTEGER PK
USERGROUPID INTEGER FK
FUNCTIONID INTEGER FK
I am curious as to why it returned 6 objects, 4 of which were null. I executed the query used by hibernate (from stdout.log) in the database client and got 2 rows back. I went ahead and used an Iterator to clean out the null objects but I was wondering if there was something I might be doing wrong that could cause this.
1. Am I doing the right thing in doing the lazy load with the following: List functionList = userGroup.getAssignedFunctionList();
2. Shouldn't the outer-join="false" ensure that I get back only those columns that are complete matches?
This is a really strange question and I don't know how else to explain it. Please let me know if I can give additional information.
TIA