Hibernate version: 1.2.0.4
I have a class which has a collection. I've mapped this collection as an idbag. However, I don't want this collection to be lazy loaded, so I define lazy=false.
I also want NHibernate to execute just one sql statement to retrieve the collection, so I define fetch="join".
My class looks like this:
Code:
public class Project : AuditableEntity<Guid>
{
public Project()
{
ProjectMembers = new List<ProjectMember> ();
}
public string Name
{
get;
set;
}
public IList<ProjectMember> ProjectMembers
{
get;
private set;
}
}
My mapping file looks like this:
Code:
<id name="Id" column="ProjectId" >
<generator class="guid"/>
</id>
<property name="Name" column="Name" />
<idbag name="ProjectMembers" table="ProjectMembers" cascade="all-delete-orphan" inverse="true" lazy="false" fetch="join">
<collection-id column="ProjectMemberId" type="Int32">
<generator class="identity"/>
</collection-id>
<key column="ProjectId" />
<composite-element class="ProjectMember">
<many-to-one name="PersonInformation" class="User" column="PersonId" fetch="join" />
<property name="MemberRole" column="RoleId" />
</composite-element>
</idbag>
When I retrieve a list of Projects, I see that one SQL statement is issued to retrieve all Projects, and then, for each project, another SQL statement is issued to retrieve the projectmembers for that Project.
How come ? I couldn't find a lot of documentation regarding the idbag ...
Or, does it have something to do with the fact that I use component mapping ?