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.  [ 4 posts ] 
Author Message
 Post subject: access attribute and mapping file issue? simple hbm
PostPosted: Fri Sep 14, 2007 9:11 pm 
Newbie

Joined: Fri Sep 14, 2007 8:51 pm
Posts: 12
Location: North Carolina
New to NHibernate. Trying to get a project up and running. I am running into one snag with configuration. I have a very simple hbm file (below). When I try to run my code I get the errors (below). The errors make it seem like NHibernate is ignoring my 'access' attribute on my properties. Seems like it is trying to use a default (getters/setters). How did I fix this? Or how do I even begin to troubleshoot this?

Thanks,
kellygreer1

Hibernate version:
NHibernate 2.2
Mapping documents:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
namespace="Doa.Domain.Entities" assembly="Doa.Domain">
<class name="Profile" table="Profiles">
<id name="Id" column="id" type="Int32" unsaved-value="-1"
access="field.camelcase-underscore">
<generator class="native" />
</id>
<property name="UserName" column="ntlogon" type="string" length="24" access="field.camelcase-underscore">
</property>
<property name="LastName" column="last_name" type="string" length="18" access="field.camelcase-underscore">
</property>
<property name="FirstName" column="first_name" type="string" length="18" access="field.camelcase-underscore">
</property>
<property name="MiddleName" column="middle_name" type="string" length="18" access="field.camelcase-underscore">
</property>
</class>
</hibernate-mapping>


Code between sessionFactory.openSession() and session.close():
I'm just using a response.write to try to write the lastname from the Profile object. The code breaks before this on:
ISessionFactory factory = cfg.BuildSessionFactory();

Full stack trace of any exception that occurs:
The following types may not be used as proxies:
Doa.Domain.Entities.Profile: method set_UserName should be virtual
Doa.Domain.Entities.Profile: method set_LastName should be virtual
Doa.Domain.Entities.Profile: method set_Id should be virtual
Doa.Domain.Entities.Profile: method get_MiddleName should be virtual
Doa.Domain.Entities.Profile: method get_UserName should be virtual
Doa.Domain.Entities.Profile: method set_FirstName should be virtual
Doa.Domain.Entities.Profile: method get_Id should be virtual
Doa.Domain.Entities.Profile: method get_FirstName should be virtual
Doa.Domain.Entities.Profile: method get_LastName should be virtual
Doa.Domain.Entities.Profile: method set_MiddleName should be virtual

Name and version of the database you are using:
SQL Server 2000


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 14, 2007 10:23 pm 
Hibernate Team
Hibernate Team

Joined: Tue Jun 13, 2006 11:29 pm
Posts: 315
Location: Calgary, Alberta, Canada
Code:
Doa.Domain.Entities.Profile: method set_UserName should be virtual
...


Make the properties virtual.

_________________
Karl Chu


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 14, 2007 11:16 pm 
Newbie

Joined: Fri Sep 14, 2007 8:51 pm
Posts: 12
Location: North Carolina
So even though the error is speaking about Methods the problem is with my Properties? I don't remember running into this last time I took NHibernate for a test drive about a year ago.

I'll try this when I get back to the office tomorrow.
I'll follow up with the results.

Thanks,
kellygreer1


Top
 Profile  
 
 Post subject:
PostPosted: Sat Sep 15, 2007 12:07 am 
Hibernate Team
Hibernate Team

Joined: Tue Jun 13, 2006 11:29 pm
Posts: 315
Location: Calgary, Alberta, Canada
Properties in .net are just syntactical sugar; they ultimately get translated to methods:
Code:
public string Username {
    get { ... }
    set { ... }
}

becomes
Code:
public string get_Username() { ... }
public void set_Username(string value) { ... }

You would not have gotten this error a year ago in NHibernate 1.0 because in NHibernate 1.2, the default changed to lazy="true" for all classes. As a result, all methods and properties in a mapped class must be virtual unless you explicitly set lazy="false"; or you specify something else (such as an interface) as its proxy.

_________________
Karl Chu


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