-->
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.  [ 2 posts ] 
Author Message
 Post subject: Insertion error while using list for collections
PostPosted: Tue Jun 27, 2006 9:48 am 
Newbie

Joined: Fri Apr 28, 2006 5:39 am
Posts: 3
Location: india
Hi,
Can anybody help me out to solve this problem.

I am using a list for collections and i am getting an error
like this while inserting a row but i am able to retrieve rows.


Additional information: Object reference not set to an instance of an object.


Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object.

These are my mapping files and classes

Transaction.hbm.xml
--------------
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="Com.VSoftcorp.Lockbox.Model.Transaction,Com.VSoftcorp.Lockbox.Model" table="LOCK_TRANSACTION_02202006_1">
<!--<id name="TransactionID" column="TRANS_ID">
<generator class="assigned" />
</id>

<many-to-one class="Com.VSoftcorp.Lockbox.Model.Batch,Com.VSoftcorp.Lockbox.Model" name="ParentBatch" not-null="true">
<column name="SITE_ID"/>
<column name="INST_ID"/>
<column name="BCH_NUM"/>
<column name="BUS_DATE"/>
</many-to-one>-->
<composite-id unsaved-value="any">
<key-property name="TransactionID" column="TRANS_ID" />
<key-many-to-one name="ParentBatch" class="Com.VSoftcorp.Lockbox.Model.Batch,Com.VSoftcorp.Lockbox.Model">
<column name="SITE_ID" />
<column name="INST_ID" />
<column name="BCH_NUM" />
<column name="BUS_DATE" />
</key-many-to-one>
</composite-id>
<property column="RECO_COMPLETE" name="RecoComplete" />

<list name="Items" table="ITEM_02202006_1" inverse="true" cascade="all-delete-orphan">
<key>
<column name="TRANS_ID" />
<column name="SITE_ID" />
<column name="INST_ID" />
<column name="BCH_NUM" />
<column name="BUS_DATE" />
</key>
<index column="SEQ_NUM"/>
<one-to-many class="Com.VSoftcorp.Lockbox.Model.Item,Com.VSoftcorp.Lockbox.Model" />

</list>

</class>
</hibernate-mapping>
Item.hbm.xml
-------
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="Com.VSoftcorp.Lockbox.Model.Item,Com.VSoftcorp.Lockbox.Model" table="ITEM_02202006_1">
<!--<id name="SequenceNumber" column="SEQ_NUM">
<generator class="assigned" />
</id> -->

<composite-id unsaved-value ="any" >
<key-property name="SequenceNumber" column="SEQ_NUM"/>
<key-many-to-one name="ParentTransaction" class="Com.VSoftcorp.Lockbox.Model.Transaction,Com.VSoftcorp.Lockbox.Model" >
<column name="TRANS_ID"/>
<column name ="SITE_ID"/>
<column name ="INST_ID"/>
<column name="BCH_NUM"/>
<column name="BUS_DATE"/>
</key-many-to-one>
</composite-id>

<!-- composite primary key support is touchy. View the documentation for syntax. -->


<property column="CUST_ACCT_NUM" name="CustomerAccountNumber"/>

</class>
</hibernate-mapping>

Transction.cs
----------------


using System;
using System.Collections;

namespace Com.VSoftcorp.Lockbox.Model
{
/// <summary>
/// Transaction class.
/// </summary>
public class Transaction
{
private IList items;
public IList Items
{
get{return items;}
set{items = value;}
}


private string reco_complete;
public string RecoComplete
{
get { return reco_complete; }

set
{
reco_complete = value;
}
}



public Transaction(int transactionID, Batch parentBatch)
{
this.transactionID = transactionID;
this.batch = parentBatch;
//this.userID = userID;
}

public override bool Equals(object obj)
{
if (obj == null) return false;
if (this == obj) return true;
Transaction other = (Transaction) obj;
return (this.TransactionID.Equals(other.TransactionID));


}

public override int GetHashCode()
{
return (this.transactionID).GetHashCode();

}

/// <summary>
/// Default constructor.
/// </summary>
public Transaction()
{}
}
}


Item.cs
-----------
using System;
using System.Collections;

namespace Com.VSoftcorp.Lockbox.Model
{
/// <summary>
/// Item type enum.
/// </summary>
//public enum ItemType{};

/// <summary>
/// Item class.
/// </summary>

public class Item
{

private long customerAccountNumber;
public long CustomerAccountNumber
{
get{return customerAccountNumber;}
set{customerAccountNumber = value;}
}

public Item(int sequenceNumber, int transactionID, int amount,
int customerAccountNumber, ItemType type, ImageParameter imageParamters)
{
this.sequenceNumber = sequenceNumber;
// this.transactionID = transactionID;
this.amount = amount;
this.customerAccountNumber = customerAccountNumber;
this.type = type;
this.imageParameter = imageParameter;
}





/// <summary>
/// Default constructor.
/// </summary>
public Item()
{}

public override bool Equals(object obj)
{
if (obj == null) return false;
if (this == obj) return true;

Item other = (Item) obj;
return (this.SequenceNumber.Equals(other.SequenceNumber) && this.ParentTransaction.Equals(other.ParentTransaction));
}

public override int GetHashCode()
{
return (this.SequenceNumber).GetHashCode();

}

}
}


Last edited by vkumar.1980@gmail.com on Tue Jun 27, 2006 10:51 am, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 27, 2006 10:23 am 
Regular
Regular

Joined: Wed Jun 21, 2006 3:13 pm
Posts: 110
Can you post a bit more of your code?

The pattern should be something like

Code:
public virtual IList TheCollection
{
  get
  {
    if(theCollection == null)
      theCollection = new ArrayList();
    return theCollection;
  }
  set
  {
    theCollection = value;
  }
}


Also, can you provide more of the stack trace? Is this happening in your code or in the NHibernate core?


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

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.