Hi Everyone!
I've got a problem with trying to setup my mappings when I've got an intermediate DB table but I've not got the same setup in C#.
What I want to do is be able to populate all the Resources assigned to a Project when I load a project.
However, when I try to create the session factory:
nhibernateConfig = new Configuration();
try
{
nhibernateConfig.AddClass(typeof(Project));
nhibernateConfig.AddClass(typeof(Resource));
try
{
nHibernateFactory = nhibernateConfig.BuildSessionFactory();
}
catch (Exception tex)
{
throw tex;
}
}
catch (MappingException ex)
{
throw ex;
}
it fails with:
Exception: Could not compile the mapping document: Test.Resource.hbm.xml"} Inner Exception: Could not find a getter for property 'ProjectResource' in class 'Test.Resource'
Any help would be most appreciated!
All the particulars are below:
Hibernate version:
2.0.1GA
Mapping documents:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
namespace="Test"
assembly="Test">
<class name="Project" table="tblProject" lazy="false">
<id name="ProjectID">
<column name="ProjectID" />
<generator class="assigned" />
</id>
<property name="Title" column="Title" />
</class>
</hibernate-mapping>
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
namespace="Test"
assembly="Test">
<class name="Resource" table="tblResource" lazy="false">
<id name="ResourceID">
<column name="ResourceID" />
<generator class="assigned" />
</id>
<property name="Name" column="Name" />
<set name="ProjectResource" table="tblProjectResource">
<key column="ResourceID"/>
<many-to-many column="ProjectID" class="Test.Project"/>
</set>
</class>
</hibernate-mapping>
namespace Test
{
public class Project
{
private int projectID;
private string title;
private List<Resource> allocatedResource;
public Project()
{}
...
}
namespace Test
{
public class Resource
{
private int resourceID;
private string name;
public Resource()
{}
...
}
CREATE TABLE tblProject (
ProjectID INT NOT NULL PRIMARY KEY IDENTITY(1,1),
Title VARCHAR(255) NOT NULL
)
CREATE TABLE tblResource (
ResourceID INT NOT NULL PRIMARY KEY IDENTITY(1,1),
Name VARCHAR(255) NOT NULL
)
CREATE TABLE tblProjectResource (
ProjectID INT NOT NULL FOREIGN KEY REFERENCES tblProject(ProjectID),
ResourceID INT NOT NULL FOREIGN KEY REFERENCES tblResource(ResourceID)
)
|