tags:

views:

1634

answers:

4

I have the following class:

public class MyClass
{
    private List<long> _myList = new List<long>();

    public virtual string MyID { get; set; }

    public virtual string MyData
    {
        get
        {
            return SomeStaticClass.Serialize(_myList);
        }
        set
        {
            _myList = SomeStaticClass.Deserialize<List<long>>(value);
        }
    }

    public virtual List<long> MyList
    {
        get { return _myList; }
    }
}

And the following mapping file:

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
               assembly="MyNamespace"
               namespace="MyNamespace">
  <class name="MyNamespace.MyClass" table="MY_TABLE">
    <id name="MyID" column="MY_ID" type="System.String">
      <generator class="assigned"></generator>
    </id>
    <property name="MyData" column="MY_DATA"></property>
  </class>
</hibernate-mapping>

When I try to run the following line:

session.Delete("From MyClass m");

I am getting a QuerySyntaxException with the message "MyClass is not mapped [From MyClass s]".

When I change the name of the "MyID" field to "ID" in the mapping file, the exception becomes

NHibernate.PropertyNotFoundException: Could not find a getter for property 'ID' in class 'MyNamespace.MyClass'.

so I am assuming it can find the mapping file. I made sure that the mapping file is an embedded resource, checked and dobule checked the namespace and class names in the mapping file. What may cause the error? I think it may relate to the MyList property which is not mapped but I am not sure since I am using non-mapped properties on my other classes without a problem.

EDIT: I tried overriding this class, with a class which has no "MyData" property and redefining "MyList" property as string. I am still receiving the same error for my overridden class.

EDIT 2: Tried with a very simple class with the same property names with same return types and only simple get; set; blocks. I still get the same error. I am almost sure that nhibernate can see my mapping files because if I change the name of a single property, it gives me PropertyNotFound instead of "class in not mapped".

A: 

it seems a bit strange you are specifying the namespace twice in the mapping file. I would try just specifying the name attribute as just "MyClass" instead of "MyNamespace.MyClass" so it would be

<class name="MyClass" table="MY_TABLE">
lomaxx
I do not know if your or mine is better but I always map like this and I had no problems until today. Also tried your suggestion but problem still continues.
Serhat Özgel
+3  A: 

How are you loading the hbms? If they are resources, make sure you've actually set the files to be embedded resources in Visual Studio

James L
I am sure they are correctly set to embedded resources and I already mentioned it in the question.
Serhat Özgel
Was having the same problem. I forgot to set my gbm mapping file to embedded resource! +1
LnDCobra
A: 

what about if you use

session.Delete("From MyNamespace.MyClass m");

I was just looking at the HQL reference and noticed in their cat example they use fully qualified objects, i.e. Eg.Cat.

lomaxx
Still the same error.
Serhat Özgel
A: 

Sorted it out now. Be careful when you get this message. There is always one more typo.

Serhat Özgel