Tommy_Shen
12-01-2006, 07:35 AM
hi, all
I have the following code:
[Test]
public void TestEditMember()
{
Member member = memberDao.Get(9L);
member.Certifications.Clear(); // caught LazyInitializationException
member.Certifications.Add(certificationDao.Get(1L) );
memberDao.Save(member);
//Certification cert = certificationDao.Get(1L);
//memberDao.AddCertification(9L, cert); it's ok.
}
Member.hbm.xml snippet:
...
<set name="Certifications" table="member_certification" lazy="true" inverse="false">
<key>
<column name="member_id" not-null="true"/>
</key>
<many-to-many class="Certification" column="certification_id"/>
</set>
...
Certification.hbm.xml snippet
....
<set name="Members" table="member_certification" lazy="true" inverse="true">
<key>
<column name="certification_id" not-null="true"/>
</key>
<many-to-many class="Certification" column="member_id"/>
</set>
....
entity relation is the normal many-to-many case.
when I call member.Certifications.Clear, I caught the following exception:
ERROR NHibernate.LazyInitializationException - Failed to lazily initialize a collection - no session
NHibernate.LazyInitializationException: Failed to lazily initialize a collection - no session
I used the TransactionProxyFactoryObject for my transaction management, can anybody help me? thanks.
PS: these codes in java worked well.
I have the following code:
[Test]
public void TestEditMember()
{
Member member = memberDao.Get(9L);
member.Certifications.Clear(); // caught LazyInitializationException
member.Certifications.Add(certificationDao.Get(1L) );
memberDao.Save(member);
//Certification cert = certificationDao.Get(1L);
//memberDao.AddCertification(9L, cert); it's ok.
}
Member.hbm.xml snippet:
...
<set name="Certifications" table="member_certification" lazy="true" inverse="false">
<key>
<column name="member_id" not-null="true"/>
</key>
<many-to-many class="Certification" column="certification_id"/>
</set>
...
Certification.hbm.xml snippet
....
<set name="Members" table="member_certification" lazy="true" inverse="true">
<key>
<column name="certification_id" not-null="true"/>
</key>
<many-to-many class="Certification" column="member_id"/>
</set>
....
entity relation is the normal many-to-many case.
when I call member.Certifications.Clear, I caught the following exception:
ERROR NHibernate.LazyInitializationException - Failed to lazily initialize a collection - no session
NHibernate.LazyInitializationException: Failed to lazily initialize a collection - no session
I used the TransactionProxyFactoryObject for my transaction management, can anybody help me? thanks.
PS: these codes in java worked well.