Hi
First of all i'm an experianced oracle developer new to OO so this problem may relate to a mis-understanding of OO that a mis-use of Nhibernate - appolgies if it's the former.
I have an abstract super class Communication that has one (more to be added) concrete sub-classes - Meeting. I also have a class Company that contains a collection of Communications. When I try to create an instance of a Company by doing :
aCompany = (Company)session.Get(typeof(Company), 1);
I get the error :
"Cannot instantiate abstract class or interface: rmeSampleApp.Communication"
I've been reading the the Bauer/King book hibernate in action and I think i've done everything correctly but obviousy l haven't. Any help would be greatly appreciated. Classes and mapping files listed below:
Mapping File :
========
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="rmeSampleApp.Communication, rmeSampleApp" table="rme_communications">
<id name="Id" column="comm_id" unsaved-value="" type="int">
<generator class="assigned" />
</id>
<property name="Title" column="comm_title"/>
<property name="Date" column="comm_date" type="date"/>
<joined-subclass name="rmeSampleApp.Meeting, rmeSampleApp" table="rme_meetings">
<key column="mtn_com_id"></key>
<property
name="Location" column="mtn_location"/>
<property
name="Type" column="mtn_type"/>
<property
name="Rating" column="mtn_rtng"/>
</joined-subclass>
</class>
<class name="rmeSampleApp.Instrument, rmeSampleApp" table="rme_instruments">
<id name="Code" column="inst_code" unsaved-value="" type="String" length="100">
<generator class="assigned" />
</id>
<property name="Sedol" column="inst_sedol"/>
<property name="Description" column="inst_desc"/>
<property name="DateFirstHeld" column="inst_first_held"/>
<property name="DateLastHeld" column="inst_last_held" />
</class>
<class name="rmeSampleApp.Company, rmeSampleApp" table="rme_companies">
<id name="Id" column="coy_code" unsaved-value="" type="int" >
<generator class="assigned" />
</id>
<property name="Name" column="coy_name"/>
<property name="Address" column="coy_address"/>
<bag name="Instruments">
<key column="inst_coy_code" />
<one-to-many
class="rmeSampleApp.Instrument, rmeSampleApp" />
</bag>
<bag name="Communications">
<key column="comm_coy_code" />
<one-to-many
class="rmeSampleApp.Communication, rmeSampleApp" />
</bag>
<!--<map name="instruments">
<key column="inst_coy_code"/>
<index column="inst_code" type="String" length ="100"/>
<one-to-many class="rmeSampleApp.Instrument, rmeSampleApp" />
</map>-->
</class>
</hibernate-mapping>
Company Class
==========
namespace rmeSampleApp
{
public class Company
{
private int _id;
public virtual int Id
{
get { return _id; }
set { _id = value; }
}
private string _name;
public virtual string Name
{
get { return _name; }
set { _name = value; }
}
private string _address;
public virtual string Address
{
get { return _address; }
set { _address = value; }
}
private IList _instruments;
public virtual IList Instruments
{
get { return _instruments; }
set { _instruments = value; }
}
private IList _communications;
public virtual IList Communications
{
get { return _communications; }
set { _communications = value; }
}
public Company()
{
Instruments = new ArrayList();
Communications = new ArrayList();
}
}
}
Communication
==========
namespace rmeSampleApp
{
public abstract class Communication
{
private int _id;
public virtual int Id
{
get { return _id; }
set { _id = value; }
}
private string _title;
public virtual string Title
{
get { return _title; }
set { _title = value; }
}
private DateTime _date;
public virtual DateTime Date
{
get { return _date; }
set { _date = value; }
}
}
}
Meeting
=====
namespace rmeSampleApp
{
public class Meeting : Communication
{
private string _location;
public virtual string Location
{
get { return _location; }
set { _location = value; }
}
private string _type;
public virtual string Type
{
get { return _type; }
set { _type = value; }
}
private string _rating;
public virtual string Rating
{
get { return _rating; }
set { _rating = value; }
}
}
}
|