tags:

views:

179

answers:

3

hello....i'm newbie developer....

i really need help at now... i just get started with Nhibernate thing at .Net... when i learn Inheritance and try it...it makes me confusing...why i get error like this :

Initializing[AP.Core.Domain.AccountPayable.APInvoice#API03/04/2010/001]-Could not initialize proxy - no Session.

this is my xml :

  <class xmlns="urn:nhibernate-mapping-2.2" mutable="true" name="AP.Core.Domain.AccountPayable.APAdjustment, AP.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" table="APAdjustment">
    <id name="AdjustmentNumber" type="System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
      <column name="AdjustmentNumber" length="17" />
      <generator class="assigned" />
    </id>
    <property name="Amount" type="System.Decimal, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
      <column name="Amount" />
    </property>
    <property name="TransactionDate" type="System.DateTime, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
      <column name="TransactionDate" />
    </property>
    <many-to-one class="AP.Core.Domain.AccountPayable.APInvoice, AP.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" lazy="proxy" name="PurchaseInvoice">
      <column name="PurchaseInvoice_id" not-null="true" />
    </many-to-one>
    <joined-subclass name="AP.Core.Domain.AccountPayable.APCreditAdjustment, AP.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" lazy="true" table="APCreditAdjustment">
      <key>
        <column name="APAdjustment_id"  />
      </key>
    </joined-subclass>
  </class>
</hibernate-mapping>

and this is inheritance Class :

Parent Class -->

public class APAdjustment
        {
        #region :FIELD
        private string adjustmentNumber;
        private decimal amount;
        private DateTime transactionDate;
        private APInvoice purchaseInvoice;

Child Class -->

public class APCreditAdjustment : APAdjustment {

  public APCreditAdjustment(){

and this my Data access :

public IList<APAdjustment> GetByNameAll()
{
   ICriteria criteria = Nhibernatesession.CreateCriteria(typeof(APAdjustment));
   return criteria.List<APAdjustment>() ;
}

My Problem is :

  1. when i load data with gridview ...it works...but i change the property to autogenerate="true" ...i missing "PurchaseInvoice" field...and i change to bind manually,and it works..when i edit that gridview ...i get this error...

    Initializing[AP.Core.Domain.AccountPayable.APInvoice#API03/04/2010/001]-Could not initialize proxy - no Session

  2. so then i change my xml ...lazy="no-proxy" ...it still work...but when edit again ...i get error again ..and i do "Comment out the selected lines" to my association "Many-to-one"...i really works it..but that's not i want...

CAN ANYBODY HELP ME...??Plizz...:(

Note : I almost forget it ,i use fluent hibernate to generate to database.From fluent Hibernate ..i put *.xml file ...so i'm work to xml NHibernate...not fluent hibernate thing...:)

A: 

This exception usually means that you are a trying to access a lazy-loaded property when the session is closed (I see lazy="proxy" in the mapping file). I suggest you to put a breakpoint before the access to "PurchaseInvoice" property and check your Session.IsOpen for the session your instance of APAdjustment belong

Regards, Marco

mCasamento
yeah...looks like my session is null...how can I fix it??I do like this... ISession session = null; ICriteria criteria = null; Boolean _check = NHibernateSession.IsOpen; try { session = NHibernateSession.SessionFactory.GetCurrentSession(); criteria = NHibernateSession.CreateCriteria(typeof(APAdjustment)); } catch (HibernateException ex) { log.Error(ex.GetBaseException()); }or did i something wrong in my code??
Ninu
A: 

If the session is null you're facing a totally different problem now (you couldn't obtain the previous error if your sesion were null, I believe you've changed something in your code) Session management need a session manager and a session context class (see nHibernate doc here) I suggest you to simplify a bit your design and don't introduce a session manager untile you've completely understood the implication (though a session manager it's a strongly recommended practices for many projects). Just open a new session like

ISession session = YouSessionFactory.OpenSession()
ICriteria criteria = session.CreateCriteria(typeof(APAdjustment));

and go forward getting rid of the SessionManager (just for testing purpose). If you're using lazy loading, the session MUST BE OPEN when your accessing the lazy loaded property, probably your session manager don't work as you expect

Regards, Marco

mCasamento
A: 

try this ... in all of your associations, put this at your code ...and maybe works..~I hope so ^_^

not-found="ignore"

Ninu