Hibernate version:
NHibernate 1.2.0.Alpha1
Mapping documents:
Code:
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0" assembly="BLL" namespace="BLL">
<class name="Movies" table="tbl_movies">
<id name="Id" column="id_movie" type="Int32" unsaved-value="any">
<generator class="sequence">
<param name="sequence">movie_id_seq</param>
</generator>
</id>
<bag name="lImg" table="tbl_img" access="field" inverse="false" lazy="true" cascade="all">
<key column="id_movie"/>
<one-to-many class="BLL.Image,BLL"/>
</bag>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0" assembly="BLL" namespace="BLL">
<class name="Image" table="tbl_img">
<id name="Id" column="id" type="Int32" unsaved-value="any">
<generator class="sequence">
<param name="sequence">img_id_seq</param>
</generator>
</id>
<property column="link" type="String" name="Link" length="100" />
<many-to-one name="Movie" class="BLL.Movie,BLL" column="id_movie" />
</class>
</hibernate-mapping>
My code
[code]
Movie class
public class Movies
{
private int id;
private IList<Imagens> lImagem;
...
}
Image class
public class Image
{
private int id;
private Movies movie;
...
}
-------------
Movie _movie = new Movie();
Ilist<Image> _list = new List<Image>;
Image _img = new Image();
_img.Link = "www.test.com"
_list.Add(_img);
_movie.lImg = _list;
ITransaction _tx = session.BeginTransaction();
session.SaveOrUpdate(_movie);
_tx.Commit(); <---- Error
ERROR
object references an unsaved transient instance - save the transient instance before flushing: BLL.Movies
[TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing: BLL.Movies]
DAL.BaseDataAccess.Save(Object __item, Boolean __pointlessParameter) in D:\Util\Reps\MovieDB\trunk\MovieDB\DAL\BaseDataAccess.cs:113
DAL.BaseDataAccess.Save(BusinessBase __item) in D:\Util\Reps\MovieDB\trunk\MovieDB\DAL\BaseDataAccess.cs:90
Facade.FilmesFacade.Save(Movies__movie) in D:\Util\Reps\MovieDB\trunk\MovieDB\Facade\FilmesFacade.cs:28
Admin_Filmes_WFCadastro.btnIncluir_Click(Object sender, EventArgs e) in d:\Util\Reps\MovieDB\trunk\MovieDB\Web\Admin\Filmes\WFCadastro.aspx.cs:67
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +105
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +107
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +7
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5102