I need help getting many to many relation to work.
my mapper file looks like
<hibernate-mapping>
<class name="com.it.cc.community.domain.ContactsDirectory" table="contactsdirectory">
<id name="directoryID" type="long" column="id" >
<generator class="increment"/>
</id>
<property name="directoryName" column="directoryname" type="string" />
<property name="directoryDescription" column="directorydescription" type="string" />
<property name="isGroupDirectory" column="isgroupdirectory" type="boolean" />
<list name="directoryContactMembers" table="directorytoperson" cascade="all" lazy="true">
<key column="directoryid" not-null="true"/>
<list-index column="dpid" />
<many-to-many column="personid" class="com.it.cc.community.domain.Person" unique="true" fetch="select"/>
</list>
</class>
</hibernate-mapping>
code to pull the the directory class with the person class that i use is as follows
Session session = SessionFactory.currentSession();
Criteria crit = session.createCriteria(getTargetClass());
crit.add(Expression.eq(session.getSessionFactory().getClassMetadata(getTargetClass()).getIdentifierPropertyName(),primaryKey));
//crit.setFetchMode("person", FetchMode.SELECT);
ContactsDirectory directory = (ContactsDirectory) crit.list().get(0);
Hibernate.initialize(directory.getDirectoryContactMembers());
//directory.setDirectoryContactMembers(ValueHandlerFactory.getValueHandlerFactory().getDirectoryValueHandler(this, directory, directory.getDirectoryID()));
SessionFactory.closeSession();
return directory;
my directorytoperson table looks like
directoryid, personid, dpid (primarykey)
all of type mediumint, and this is using mysql.
My problem is that when i call this code, i get like 70 null objects, and 1 which is the actual object to be retrieved. What am i doing wrong? why do i keep pulling up so many null objects?
|