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: Mapping with an intermediate table
PostPosted: Mon Feb 09, 2009 3:51 pm 
Newbie

Joined: Mon Feb 02, 2009 12:36 pm
Posts: 2
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)
)


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 10, 2009 8:13 am 
Hi..
Check out your property names, and get/set methods.
I think you wrote some wrong.

[]s


Top
  
 
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.