-->
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.  [ 3 posts ] 
Author Message
 Post subject: Beginner has problem with abstract class
PostPosted: Thu Sep 14, 2006 10:09 am 
Beginner
Beginner

Joined: Wed Jul 26, 2006 11:52 am
Posts: 23
Location: Edinburgh, Scotland
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; }
}
}
}


Top
 Profile  
 
 Post subject: Error found
PostPosted: Mon Oct 30, 2006 4:16 pm 
Beginner
Beginner

Joined: Wed Aug 09, 2006 10:15 am
Posts: 20
Location: Vitoria - ES - Brazil
Hi, You forgot to map your Meeting Class.

Meeting Class is the concrete class in your hierarchy, if Hibernate canĀ“t find it, the parent class ( which is absrtact ) will be instanciated.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 31, 2006 5:34 am 
Beginner
Beginner

Joined: Wed Jul 26, 2006 11:52 am
Posts: 23
Location: Edinburgh, Scotland
Thanks I got this sorted a while abog but socred you anyway..


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.