-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Invalid index N for this SqlParameterCollection with Count=N
PostPosted: Tue Aug 02, 2011 6:08 pm 
Newbie

Joined: Tue Aug 02, 2011 3:34 pm
Posts: 2
Hi,
I have problems inserting data with a many-to many relation as follows

Code:
table Company
{
int SysId
...
}

Premise
{
int SysId
...
}
CompanyPremise
{
int CompanyId,
int PremiseId
/*Both form composite primary key*/
}

Entity calses
public class Premise
{
public Premise( )
public virtual  IList<CompanyPremise> CompanYPremises{ get; set; }
....
}
public PremiseMap()
{
      Table("Premise");
      LazyLoad();
      Id(x => x.SysId).GeneratedBy.Identity().Column("SysId");
     .....
    HasMany(x => x.CompanyPremises);
}

public class Company
  {
    public Company()
    {
    }
    public virtual int SysId { get; set; }
    public virtual IList<CompanyPremise> CompanyPremises { get; set; }
...
}

public class CompanyPremise
  {
    public CompanyPremise() { }
    public virtual int CompanyId { get; set; }
    public virtual int PremiseId { get; set; }
    public virtual Company Company { get; set; }
    public virtual Premise Premise { get; set; }
}

public class CompanyPremiseMap : ClassMap<CompanyPremise>
  {

    public CompanyPremiseMap()
    {
      Table("CompanyPremise");
      LazyLoad();
      CompositeId().KeyProperty(x => x.CompanyId).KeyProperty(x => x.PremiseId);
      References(x => x.Company).Column("CompanyId");
      References(x => x.Premise).Column("PremiseId");
    }

  }

public CompanyMap()
    {
      Table("Company");
      LazyLoad();
      Id(x => x.SysId).GeneratedBy.Identity().Column("SysId");
      HasMany(x => x.CompanyPremises);
}


I am trying to insert into CompanyPremise table like this
Code:
var trans =session.BeginTransaction();     
var cm = session.Get<Company>( companyId );
      var pm = session.Get<Premise>( premiseId );     
      var cp = new CompanyPremise
      {
        Company = cm,
        Premise = pm       
      };     
      session.SaveOrUpdate( cp );
transaction.Commit();


This does not work. Everything is fine utill Commit( );
When it throws an exception:
Invalid index 2 for this SqlParameterCollection with Count=2

I am pulling my hair out. Entire day and I have no idea what I am doing wrong

Please help!!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.