-->
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.  [ 1 post ] 
Author Message
 Post subject: Problem trying to set property type by reflection, Could not
PostPosted: Thu Aug 11, 2011 6:59 am 
Newbie

Joined: Thu Aug 11, 2011 6:06 am
Posts: 3
Good afternoon,

I am new to NHibernate. I would like to implement a testing web application using this technologie. I got the following error [Exception:{"Could not compile the mapping document: TelDir.Core.Domain.Position.hbm.xml"}
Message:{"Problem trying to set property type by reflection"}
] while I trying to add a new Position to Database with the following code


Code:
     
            Position p = new Position("Developer");
            IPositionRepository repository = new PositionRepository();
            repository.Add(p);




I have the following database schemas:

Code:
/*  SQL 2005 Syntax */
/*----------------------------------- tblDepartment ------------------------------------*/

CREATE TABLE [dbo].[tblDepartment](
   [DepartmentID] [int] IDENTITY(1,1) NOT NULL,
   [DepartmentName] [varchar](10) NOT NULL,
   [GroupID] [int] NULL,
CONSTRAINT [PK_tblDepartment] PRIMARY KEY CLUSTERED
(
   [DepartmentID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[tblDepartment]  WITH CHECK ADD  CONSTRAINT [FK_tblDepartment_tblGroup] FOREIGN KEY([GroupID])
REFERENCES [dbo].[tblGroup] ([GroupID])
GO
ALTER TABLE [dbo].[tblDepartment] CHECK CONSTRAINT [FK_tblDepartment_tblGroup]
GO

/*----------------------------------- tblGroup --------------------------------------*/

CREATE TABLE [dbo].[tblGroup](
   [GroupID] [int] IDENTITY(1,1) NOT NULL,
   [GroupName] [varchar](50) NOT NULL,
CONSTRAINT [PK_tblGroup] PRIMARY KEY CLUSTERED
(
   [GroupID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO

/*----------------------------------- tblPosition --------------------------------------*/

CREATE TABLE [dbo].[tblPosition](
   [PositionID] [int] IDENTITY(1,1) NOT NULL,
   [PositionName] [varchar](255) NULL,
CONSTRAINT [PK_tblPosition] PRIMARY KEY CLUSTERED
(
   [PositionID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO

/*----------------------------------- tblMember --------------------------------------*/

CREATE TABLE [dbo].[tblMember](
   [MemberID] [int] IDENTITY(1,1) NOT NULL,
   [MemberFirstName] [varchar](50) NULL,
   [MemberLastName] [varchar](50) NULL,
   [MemberFullName] [varbinary](50) NOT NULL,
   [Extention] [varchar](50) NULL,
   [OfficePhone] [varbinary](50) NULL,
   [FirstMobilePhone] [varbinary](50) NULL,
   [SecondMobilePhone] [varchar](50) NULL,
   [ThirdMobilePhone] [varchar](50) NULL,
   [Email] [varchar](50) NULL,
   [GroupID] [int] NULL,
   [DepartmentID] [int] NULL,
   [PositionID] [int] NULL,
CONSTRAINT [PK_tblMember] PRIMARY KEY CLUSTERED
(
   [MemberID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO

ALTER TABLE [dbo].[tblMember]  WITH CHECK ADD  CONSTRAINT [FK_tblMember_tblDepartment] FOREIGN KEY([DepartmentID])
REFERENCES [dbo].[tblDepartment] ([DepartmentID])
GO
ALTER TABLE [dbo].[tblMember] CHECK CONSTRAINT [FK_tblMember_tblDepartment]
GO
ALTER TABLE [dbo].[tblMember]  WITH CHECK ADD  CONSTRAINT [FK_tblMember_tblGroup] FOREIGN KEY([GroupID])
REFERENCES [dbo].[tblGroup] ([GroupID])
GO

ALTER TABLE [dbo].[tblMember] CHECK CONSTRAINT [FK_tblMember_tblGroup]
GO

ALTER TABLE [dbo].[tblMember]  WITH CHECK ADD  CONSTRAINT [FK_tblMember_tblPosition] FOREIGN KEY([PositionID])
REFERENCES [dbo].[tblPosition] ([PositionID])
GO

ALTER TABLE [dbo].[tblMember] CHECK CONSTRAINT [FK_tblMember_tblPosition]
GO




My hbm.xml definition


Department.hbm.xml
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
  <class name="TelDir.Core.Domain.Department, TelDir.Core" table="tblDepartment" lazy="false">
    <id name="ID" column="DepartmentID" unsaved-value="0">
      <generator class="identity" />
    </id>

    <property name="DepartmentName" column="DepartmentName" />   

    <many-to-one name="Group" class="Group" column="GroupId" />
    <bag name="Members" table="tblMember" inverse="true">
      <key column="DepartmentID" />
      <one-to-many class="TelDir.Core.Domain.Member, TelDir.Core" />
    </bag>
  </class>
</hibernate-mapping>


Group.hbm.xml
Code:
<?xml version="1.0" encoding="utf-8" ?>
<class name="TelDir.Core.Domain.Group, TelDir.Core" table="tblGroup" lazy="false">
  <id name="ID" column="GroupID" unsaved-value="0">
    <generator class="identity" />
  </id>

  <property name="GroupName" column="GroupName" />

  <bag name="Members" table="tblMember" inverse="true">
    <key column="GroupID" />
    <one-to-many class="TelDir.Core.Domain.Group, TelDir.Core" />
  </bag>
  <bag name="Departments" table="tblDepartment" inverse="true">
    <key column="GroupID" />
    <one-to-many class="TelDir.Core.Domain.Department, TelDir.Core" />
  </bag>
</class>


Position.hbm.xml
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
  <class name="TelDir.Core.Domain.Position, TelDir.Core" table="tblPosition" lazy="false">
    <id name="ID" column="PositionID" unsaved-value="0">
      <generator class="identity" />
    </id>

    <property name="PositionName" column="PositionName" />   

    <bag name="Members" table="tblMember" inverse="true">
      <key column="PositionID" />
      <one-to-many class="TelDir.Core.Domain.Member, TelDir.Core" />
    </bag>
  </class>
</hibernate-mapping>


Member.hbm.xml
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
  <class name="TelDir.Core.Domain.Member, TelDir.Core" table="tblMember" lazy="false">
    <id name="ID" column="MemberID" unsaved-value="0">
      <generator class="identity" />
    </id>

    <property name="MemberFirstName" column="MemberFirstName" />
    <property name="MemberLastName" column="MemberLastName" />
    <property name="MemberFullName" column="MemberFullName" />
    <property name="Extention" column="Extention" />
    <property name="OfficePhone" column="OfficePhone" />
    <property name="FirstMobilePhone" column="FirstMobilePhone" />
    <property name="SecondMobilePhone" column="SecondMobilePhone" />
    <property name="ThirdMobilePhone" column="ThirdMobilePhone" />
    <property name="Email" column="Email" />

    <many-to-one name="Position" class="TelDir.Core.Domain.Position, TelDir.Core" column="PositionID" />
    <many-to-one name="Group" class="TelDir.Core.Domain.Group, TelDir.Core" column="GroupID" />
    <many-to-one name="Department" class="TelDir.Core.Domain.Department, TelDir.Core" column="DepartmentID" />

  </class>
</hibernate-mapping>




And here are the class definition




Department.cs

Code:
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Text;
using TelDir.Core.Utils;

namespace TelDir.Core.Domain
{
    public class Department:DomainObject<long>
    {
        private string _DepartmentName = "";
        private Group _group;
        private IList<Member> _members = new List<Member>(); 

        private Department() { }

        public Department(string dptName) {
            _DepartmentName = dptName;
        }

        public string DepartmentName {
            get { return _DepartmentName; }
            set {
                Check.Require(!string.IsNullOrEmpty(value), "A valid department name must be provided");   
                _DepartmentName = value;
            }
        }

        public Group BeingInGroup {
            get { return _group; }
            set { _group = value; }
        }

        public virtual void AddMember(Member mem)        {
            if (!_members.Contains(mem))            {
                _members.Add(mem);
            }
        }

        public virtual void RemoveMember(Member mem)        {
            if (_members.Contains(mem))            {
                _members.Remove(mem);
            }
        }

        public ReadOnlyCollection<Member> Members        {
            get { return new ReadOnlyCollection<Member>(_members); }
            protected set { _members = value; }
        }
    }
}



Group.cs

Code:
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Text;

namespace TelDir.Core.Domain
{
    public class Group:DomainObject<long>
    {
        private string _GroupName = "";
        private IList<Member> _members = new List<Member>();
        private IList<Department> _departments = new List<Department>();


        private Group(){}

        public Group(string grpname) {
            _GroupName = grpname;
        }

        public string GroupName {
            get { return _GroupName; }
            set { _GroupName = value; }
        }


        public virtual void AddMember(Member mem)        {
            if (!_members.Contains(mem)){
                _members.Add(mem);
            }
        }

        public virtual void RemoveMember(Member mem)        {
            if (_members.Contains(mem)) {
                _members.Remove(mem);
            }
        }

        public virtual void AddDepartment(Department dpt)        {
            if (!_departments.Contains(dpt))            {
                _departments.Add(dpt);
            }
        }

        public virtual void RemoveDepartment(Department dpt)        {
            if (_departments.Contains(dpt))            {
                _departments.Remove(dpt);
            }
        }



        public ReadOnlyCollection<Member> Members        {
            get { return new ReadOnlyCollection<Member >(_members); }
        }

        public ReadOnlyCollection<Department> Departments {
            get { return new ReadOnlyCollection<Department>(_departments); }
        }

    }
}



Position.cs

Code:
using System;
using System.Collections.Generic;
using System.Text;

namespace TelDir.Core.Domain
{
    public class Position: DomainObject<string>
    {
        private string _positionname = "";
        private IList<Member> _members = new List<Member>(); 

       
        private Position(){ }

        public Position(string positionname) {
            _positionname = positionname;
        }

        public IList<Member> Members        {
            get { return new List<Member>(_members).AsReadOnly(); }
            protected set { _members = value; }
        }

        public void AddMember(Member member)        {
            if (member != null && !_members.Contains(member))            {
                _members.Add(member);
            }
        }

        public void RemoveMember(Member member)        {
            if (member != null && _members.Contains(member))            {
                _members.Remove(member);
            }
        }
    }
}


Member.cs

Code:
using System;
using System.Collections.Generic;
using System.Text;

namespace TelDir.Core.Domain
{
    public class Member:DomainObject<long>
    {
        private string _MemberFirstName="";
        private string _MemberLastName="";
        private string _MemberFullName="";
        private string _Extention="";
        private string _OfficePhone="";
        private string _FirstMobilePhone="";
        private string _SecondMobilePhone="";
        private string _ThirdMobilePhone="";
        private string _Email="";

        private Department _department;
        private Group _group;
        private Position _position;



        private Member() { }

        public Member(string fullname) {
            _MemberFullName = fullname;
        }

        public string MemberFirstName {
            get { return _MemberFirstName; }
            set { _MemberFirstName = value; }
        }
        public string MemberLastName {
            get { return _MemberLastName; }
            set { _MemberLastName = value; }
        }
        public string MemberFullName {
            get { return _MemberFullName; }
            set { _MemberFullName = value; }
        }
        public string Extention {
            get { return _Extention; }
            set { _Extention = value; }
        }
        public string OfficePhone {
            get { return _OfficePhone; }
            set { _OfficePhone = value; }
        }
        public string FirstMobilePhone {
            get { return _FirstMobilePhone; }
            set { _FirstMobilePhone = value;}
        }
        public string SecondMobilePhone {
            get { return _SecondMobilePhone; }
            set { _SecondMobilePhone = value; }
        }
        public string ThirdMobilePhone {
            get { return _ThirdMobilePhone; }
            set { _ThirdMobilePhone = value; }
        }
        public string Email {
            get { return _Email; }
            set { _Email = value; }
        }

        public Department Department {
            get { return _department; }
            set { _department = value; }
        }
        public  Group Group {
            get { return _group; }
            set { _group = value; }
        }
        public Position Position {
            get { return _position; }
            set { _position = value; }
        }


    }
}




Sorry for the full of code, but I would like you to see in detail of what my coding is so that it is more easy to see what is the cause of the problem.


Best regards,


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

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.