PDA

View Full Version : NHibernate "Failed to lazily initialize a collection"


winx
04-11-2007, 02:56 PM
Hi,

if i want to delete data with nhibernate from my MySQL Application
i always got a "Failed to lazily initialize a collection" error...
can somebody help me?


public void MakeTransient(MovieSpringApp.Domain.Verein verein)
{
this.HibernateTemplate.Delete(verein);
}


The table got an one-to-many relation to my 2.table


<class name="MovieSpringApp.Domain.Verein, MovieSpringApp" table="vereine" lazy="false">
<id name="ID" column="id" type="Int32">
<generator class="native"/>
</id>
<property name="Name" column="verein" type="String"/>
<bag name="SpielerListe" inverse="true" lazy="true" cascade="all">
<key column="deptid"/>
<one-to-many class="MovieSpringApp.Domain.Spieler, MovieSpringApp"/>
</bag>
</class>

<class name="MovieSpringApp.Domain.Spieler, MovieSpringApp" table="spieler" lazy="false">
<id name="ID" column="id" type="Int32">
<generator class="native"/>
</id>
<property name="Name" column="name" type="String"/>
<property name="Nummer" column="nummer" type="Int32"/>
<many-to-one name="Verein" class="MovieSpringApp.Domain.Verein, MovieSpringApp">
<column name="fk_verein" length="5" sql-type="Int32" not-null="false" index="fk_verein"/>
</many-to-one>
</class>



Can somebody give me a hint?

Thx,
winx

boriska
04-12-2007, 08:43 AM
Hi,

try to search in the spring.net forum for osiv(OpenSessionInView) or lazy or session scope or Flush.
The hint is ... if you use the lazy initialization with the spring.net + nhibernate you have to consider transactions.

Hope this helps

Regards,
Boris