-->
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.  [ 5 posts ] 
Author Message
 Post subject: How to Proxy using an Interface?
PostPosted: Mon Sep 12, 2005 6:03 pm 
Senior
Senior

Joined: Thu Jun 02, 2005 5:03 pm
Posts: 135
Location: Paris
I'm interested in how to use an interface as a proxy rather than having to make all the properties and methods of a class virtual. I'd really prefer to have sealed classes.

When I try to use an interface as a proxy I'm getting an error when trying to build a SessionFactory:

Code:
NHibernate.Impl.SessionFactoryImpl: 2005-09-12 10:18:48,672 [5788] DEBUG NHibernate.Impl.SessionFactoryImpl [(null)] <(null)> - instantiating session factory with properties: {hibernate.dialect=NHibernate.Dialect.MsSql2000Dialect, hibernate.query.substitutions=true 1, false 0, hibernate.connection.connection_string=Data source=SROTTEM\VSDotNet;Initial Catalog=Framework;User Id=sa;Password=sqladmin, hibernate.connection.provider=NHibernate.Connection.DriverConnectionProvider, hibernate.connection.driver_class=NHibernate.Driver.SqlClientDriver}
Object reference not set to an instance of an object.
   at NHibernate.PropertyNotFoundException..ctor(Type type, String fieldName)
   at NHibernate.Property.FieldAccessor.GetField(Type type, String fieldName)
   at NHibernate.Property.FieldAccessor.GetField(Type type, String fieldName)
   at NHibernate.Property.FieldAccessor.GetGetter(Type theClass, String propertyName)
   at NHibernate.Mapping.Property.GetGetter(Type clazz)
   at NHibernate.Persister.AbstractEntityPersister..ctor(PersistentClass model, ISessionFactoryImplementor factory)
   at NHibernate.Persister.EntityPersister..ctor(PersistentClass model, ISessionFactoryImplementor factory)
   at NHibernate.Persister.PersisterFactory.CreateClassPersister(PersistentClass model, ISessionFactoryImplementor factory)
   at NHibernate.Impl.SessionFactoryImpl..ctor(Configuration cfg, Settings settings)
   at NHibernate.Cfg.Configuration.BuildSessionFactory()
   at Framework.Core.Repository..ctor(String dbConnectionString) in C:\Documents and Settings\Symon\My Documents\Visual Studio Projects\Framework.Core\Repository.cs:line 79
   at Framework.Core.Tests.FullPrivilegeTestCase.TestFixtureSetup() in C:\Documents and Settings\Symon\My Documents\Visual Studio Projects\Framework.Tests\FullPrivilegeTestCase.cs:line 117



I've just added a proxy attribute to the class referring to the interface for the class.

Anyone got any information on this?

Cheers,

Symon.


Last edited by s.rottem on Tue Sep 13, 2005 1:56 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 13, 2005 1:55 pm 
Senior
Senior

Joined: Thu Jun 02, 2005 5:03 pm
Posts: 135
Location: Paris
I'm wondering whether maybe this is caused by trying to use an interface as a proxy when using access="field". My classes implement a private field as the NHibernate accessor but the interface only contains the definitions of the public properties (my NHibernate accessors all use a lowercase first letter while my public properies all use uppercase first letters).

Maping file:
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0" namespace="Framework.Core.Entities" assembly="Framework.Core">

   <class name="AccessControl" table="AccessControl" proxy="Framework.Core.Proxies.IAccessControl, Framework.Core" lazy="true">
      
      <id name="id" column="AccessControlID" unsaved-value="0" access="field">
         <generator class="native" />
      </id>
      
      <property name="sourceIPAddress" column="SourceIPAddress" length="50" access="field"/>
      
   </class>
   
</hibernate-mapping>


Proxy interface:
Code:
   public interface IAccessControl
   {
      int Id
      {
         get;
      }

      string SourceIPAddress
      {
         get;
         set;
      }

   }


Concrete class:
Code:
public class AccessControl
{   
   //NHibernate Accessors
   private int         id            = 0;
   private string      sourceIPAddress   = null;

   public int Id
   {
      get { return id;}
   }
   
   public string SourceIPAddress
   {
      get { return sourceIPAddress; }
      set { sourceIPAddress = value; }
   }
}


Is it possible that this is the cause of the problem?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 13, 2005 3:42 pm 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
This is fixed in CVS, it should have reported the missing property name, but instead a NullReferenceException is thrown from the exception constructor. Try checking the spelling of field names manually.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 13, 2005 3:45 pm 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
s.rottem wrote:
I'm wondering whether maybe this is caused by trying to use an interface as a proxy when using access="field".

...

Is it possible that this is the cause of the problem?


Yes, now I think this is indeed the case.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 13, 2005 5:56 pm 
Senior
Senior

Joined: Thu Jun 02, 2005 5:03 pm
Posts: 135
Location: Paris
DOH!

I take it that there's no workaround? If using an interface as a proxy then the NHibernate accessors <b>must</b> be the properties defined in the interface?

Symon.


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